Fixed some embarassing errors

svn path=/trunk/; revision=2961
This commit is contained in:
KJK::Hyperion 2002-05-17 01:55:34 +00:00
parent a2da78fa4e
commit d24e468cb0
5 changed files with 87 additions and 17 deletions

View file

@ -1,4 +1,4 @@
/* $Id: fcntl.c,v 1.4 2002/03/21 22:41:53 hyperion Exp $ /* $Id: fcntl.c,v 1.5 2002/05/17 01:54:39 hyperion Exp $
*/ */
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
@ -35,19 +35,29 @@ int fcntl(int fildes, int cmd, ...)
/* lock the environment */ /* lock the environment */
__PdxAcquirePdataLock(); __PdxAcquirePdataLock();
INFO("environment locked");
/* get the file descriptors table */ /* get the file descriptors table */
pftFdTable = &__PdxGetProcessData()->FdTable; pftFdTable = &__PdxGetProcessData()->FdTable;
INFO("file descriptors table at 0x%08X", pftFdTable);
/* fildes is an invalid, closed or uninitialized descriptor */ /* fildes is an invalid descriptor, or it's a closed or uninitialized
descriptor and the requested operation is not the creation of a new
descriptor */
if if
( (
fildes < 0 || fildes < 0 ||
fildes >= OPEN_MAX || fildes >= OPEN_MAX ||
__fdtable_entry_isavail(pftFdTable, fildes) == 0 || (
__fdtable_entry_get(pftFdTable, fildes) == 0 (cmd != F_NEWFD) &&
(
__fdtable_entry_isavail(pftFdTable, fildes) == 0 ||
__fdtable_entry_get(pftFdTable, fildes) == 0
)
)
) )
{ {
INFO("invalid file descriptor");
errno = EBADF; errno = EBADF;
__PdxReleasePdataLock(); __PdxReleasePdataLock();
return (-1); return (-1);
@ -55,6 +65,7 @@ int fcntl(int fildes, int cmd, ...)
/* get the file descriptor referenced by fildes */ /* get the file descriptor referenced by fildes */
pfdDescriptor = __fdtable_entry_get(pftFdTable, fildes); pfdDescriptor = __fdtable_entry_get(pftFdTable, fildes);
INFO("file descriptor %d at 0x%08X", fildes, pftFdTable);
/* get third argument as integer */ /* get third argument as integer */
va_start(vlArgs, cmd); va_start(vlArgs, cmd);
@ -75,12 +86,17 @@ int fcntl(int fildes, int cmd, ...)
{ {
int nDupFileNo; int nDupFileNo;
__fildes_t *pfdDupDescriptor; __fildes_t *pfdDupDescriptor;
INFO("requested operation: F_DUPFD");
/* allocate the duplicated descriptor */ /* allocate the duplicated descriptor */
nDupFileNo = __fdtable_entry_add(pftFdTable, nThirdArg, 0, &pfdDupDescriptor); nDupFileNo = __fdtable_entry_add(pftFdTable, nThirdArg, 0, &pfdDupDescriptor);
if(nDupFileNo) if(nDupFileNo)
{
ERR("__fdtable_entry_add() failed, errno %d", errno);
break; break;
}
/* copy the open flags */ /* copy the open flags */
pfdDupDescriptor->OpenFlags = pfdDescriptor->OpenFlags; pfdDupDescriptor->OpenFlags = pfdDescriptor->OpenFlags;
@ -147,12 +163,14 @@ int fcntl(int fildes, int cmd, ...)
case F_GETFD: case F_GETFD:
{ {
INFO("requested operation: F_GETFD");
nRetVal = pfdDescriptor->FdFlags; nRetVal = pfdDescriptor->FdFlags;
break; break;
} }
case F_SETFD: case F_SETFD:
{ {
INFO("requested operation: F_SETFD");
pfdDescriptor->FdFlags = nThirdArg; pfdDescriptor->FdFlags = nThirdArg;
nRetVal = 0; nRetVal = 0;
break; break;
@ -160,12 +178,14 @@ int fcntl(int fildes, int cmd, ...)
case F_GETFL: case F_GETFL:
{ {
INFO("requested operation: F_GETFL");
nRetVal = pfdDescriptor->OpenFlags; nRetVal = pfdDescriptor->OpenFlags;
break; break;
} }
case F_SETFL: case F_SETFL:
{ {
INFO("requested operation: F_SETFL");
pfdDescriptor->OpenFlags = nThirdArg; pfdDescriptor->OpenFlags = nThirdArg;
nRetVal = 0; nRetVal = 0;
break; break;
@ -173,24 +193,28 @@ int fcntl(int fildes, int cmd, ...)
case F_GETLK: case F_GETLK:
{ {
INFO("requested operation: F_GETLK");
errno = EINVAL; errno = EINVAL;
break; break;
} }
case F_SETLK: case F_SETLK:
{ {
INFO("requested operation: F_SETLK");
errno = EINVAL; errno = EINVAL;
break; break;
} }
case F_SETLKW: case F_SETLKW:
{ {
INFO("requested operation: F_SETLKW");
errno = EINVAL; errno = EINVAL;
break; break;
} }
case F_NEWFD: case F_NEWFD:
{ {
INFO("requested operation: F_NEWFD");
/* allocate a new descriptor */ /* allocate a new descriptor */
nRetVal = __fdtable_entry_add(pftFdTable, fildes, (__fildes_t *)pThirdArg, 0); nRetVal = __fdtable_entry_add(pftFdTable, fildes, (__fildes_t *)pThirdArg, 0);
break; break;
@ -198,6 +222,7 @@ int fcntl(int fildes, int cmd, ...)
case F_DELFD: case F_DELFD:
{ {
INFO("requested operation: F_DELFD");
/* invalid return pointer */ /* invalid return pointer */
if(pThirdArg == 0) if(pThirdArg == 0)
{ {
@ -214,6 +239,7 @@ int fcntl(int fildes, int cmd, ...)
case F_GETALL: case F_GETALL:
{ {
INFO("requested operation: F_GETALL");
/* invalid return pointer */ /* invalid return pointer */
if(pThirdArg == 0) if(pThirdArg == 0)
{ {
@ -224,10 +250,13 @@ int fcntl(int fildes, int cmd, ...)
/* return a copy of the file descriptor */ /* return a copy of the file descriptor */
memcpy((__fildes_t *)pThirdArg, pfdDescriptor, sizeof(*pfdDescriptor)); memcpy((__fildes_t *)pThirdArg, pfdDescriptor, sizeof(*pfdDescriptor));
nRetVal = 0; nRetVal = 0;
break;
} }
case F_SETALL: case F_SETALL:
{ {
INFO("requested operation: F_SETALL");
/* invalid file descriptor to copy attributes from */ /* invalid file descriptor to copy attributes from */
if(pThirdArg == 0) if(pThirdArg == 0)
{ {
@ -238,10 +267,13 @@ int fcntl(int fildes, int cmd, ...)
/* copy the attributes of file descriptor from the provided descriptor */ /* copy the attributes of file descriptor from the provided descriptor */
memcpy(pfdDescriptor, pThirdArg, sizeof(*pfdDescriptor)); memcpy(pfdDescriptor, pThirdArg, sizeof(*pfdDescriptor));
nRetVal = 0; nRetVal = 0;
break;
} }
case F_GETXP: case F_GETXP:
{ {
INFO("requested operation: F_GETXP");
/* invalid return pointer */ /* invalid return pointer */
if(pThirdArg == 0) if(pThirdArg == 0)
{ {
@ -252,11 +284,13 @@ int fcntl(int fildes, int cmd, ...)
/* return a pointer to the extra data associated to the descriptor */ /* return a pointer to the extra data associated to the descriptor */
*((void **)pThirdArg) = pfdDescriptor->ExtraData; *((void **)pThirdArg) = pfdDescriptor->ExtraData;
nRetVal = 0; nRetVal = 0;
break; break;
} }
case F_SETXP: case F_SETXP:
{ {
INFO("requested operation: F_SETXP");
/* set the pointer to the extra data associated */ /* set the pointer to the extra data associated */
pfdDescriptor->ExtraData = pThirdArg; pfdDescriptor->ExtraData = pThirdArg;
nRetVal = 0; nRetVal = 0;
@ -265,12 +299,14 @@ int fcntl(int fildes, int cmd, ...)
case F_GETXS: case F_GETXS:
{ {
INFO("requested operation: F_GETXS");
nRetVal = pfdDescriptor->ExtraDataSize; nRetVal = pfdDescriptor->ExtraDataSize;
break; break;
} }
case F_SETXS: case F_SETXS:
{ {
INFO("requested operation: F_SETXS");
pfdDescriptor->ExtraDataSize = nThirdArg; pfdDescriptor->ExtraDataSize = nThirdArg;
nRetVal = 0; nRetVal = 0;
break; break;
@ -278,6 +314,7 @@ int fcntl(int fildes, int cmd, ...)
case F_GETFH: case F_GETFH:
{ {
INFO("requested operation: F_GETFH");
/* invalid return pointer */ /* invalid return pointer */
if(pThirdArg == 0) if(pThirdArg == 0)
{ {
@ -293,17 +330,20 @@ int fcntl(int fildes, int cmd, ...)
case F_SETFH: case F_SETFH:
{ {
INFO("requested operation: F_SETFH");
pfdDescriptor->FileHandle = pThirdArg; pfdDescriptor->FileHandle = pThirdArg;
nRetVal = 0; nRetVal = 0;
break; break;
} }
default: default:
INFO("invalid operation requested");
errno = EINVAL; errno = EINVAL;
} }
/* unlock the environment */ /* unlock the environment */
__PdxReleasePdataLock(); __PdxReleasePdataLock();
INFO("environment unlocked");
return (nRetVal); return (nRetVal);
} }

View file

@ -1,4 +1,4 @@
/* $Id: open.c,v 1.2 2002/02/20 09:17:57 hyperion Exp $ /* $Id: open.c,v 1.3 2002/05/17 01:54:39 hyperion Exp $
*/ */
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
@ -52,7 +52,6 @@ int _Wopen(const wchar_t *path, int oflag, ...)
mode_t mFileMode; mode_t mFileMode;
#endif #endif
int nFileNo; int nFileNo;
__fdtable_t *pftTable;
__fildes_t fdDescriptor; __fildes_t fdDescriptor;
/* translate file access flag */ /* translate file access flag */
@ -131,9 +130,9 @@ int _Wopen(const wchar_t *path, int oflag, ...)
0, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nCreateDisposition, nCreateDisposition,
FILE_SYNCHRONOUS_IO_NONALERT, nCreateOptions | FILE_SYNCHRONOUS_IO_NONALERT,
NULL, NULL,
nCreateOptions 0
); );
/* failure */ /* failure */

View file

@ -1,4 +1,4 @@
/* $Id: fdtable.c,v 1.3 2002/03/11 20:48:08 hyperion Exp $ /* $Id: fdtable.c,v 1.4 2002/05/17 01:54:39 hyperion Exp $
*/ */
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
@ -155,11 +155,14 @@ int __fdtable_entry_add(__fdtable_t * fdtable, int fileno, __fildes_t * fildes,
); );
/* ... try to increase the size of the table */ /* ... try to increase the size of the table */
pTemp = __realloc if(fdtable->AllocatedDescriptors * sizeof(*fdtable->Descriptors) == 0)
( pTemp = __malloc((nFileNo + 1) * sizeof(*fdtable->Descriptors));
fdtable->Descriptors, else
(nFileNo + 1) * sizeof(*fdtable->Descriptors) pTemp = __realloc
); (
fdtable->Descriptors,
(nFileNo + 1) * sizeof(*fdtable->Descriptors)
);
/* reallocation failed */ /* reallocation failed */
if(pTemp == 0) if(pTemp == 0)

View file

@ -1,4 +1,4 @@
/* $Id: getpid.c,v 1.2 2002/02/20 09:17:58 hyperion Exp $ /* $Id: getpid.c,v 1.3 2002/05/17 01:55:34 hyperion Exp $
*/ */
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
@ -13,10 +13,32 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <psx/errno.h>
pid_t getpid(void) pid_t getpid(void)
{ {
return ((pid_t)NtCurrentTeb()->Cid.UniqueThread); PROCESS_BASIC_INFORMATION pbiInfo;
NTSTATUS nErrCode;
nErrCode = NtQueryInformationProcess
(
NtCurrentProcess(),
ProcessBasicInformation,
&pbiInfo,
sizeof(pbiInfo),
NULL
);
if(!NT_SUCCESS(nErrCode))
{
errno = __status_to_errno(nErrCode);
return (0);
}
return (pbiInfo.UniqueProcessId);
#if 0
return ((pid_t)NtCurrentTeb()->Cid.UniqueProcess);
#endif
} }
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: write.c,v 1.3 2002/03/21 22:46:30 hyperion Exp $ /* $Id: write.c,v 1.4 2002/05/17 01:54:39 hyperion Exp $
*/ */
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
@ -29,13 +29,18 @@ ssize_t write(int fildes, const void *buf, size_t nbyte)
return (0); return (0);
if(fcntl(fildes, F_GETALL, &fdDescriptor) == -1) if(fcntl(fildes, F_GETALL, &fdDescriptor) == -1)
{
ERR("fcntl() failed, errno %d", errno);
return (0); return (0);
}
if((fdDescriptor.OpenFlags && O_APPEND) == O_APPEND) if((fdDescriptor.OpenFlags && O_APPEND) == O_APPEND)
{ {
TODO("move file pointer to the end"); TODO("move file pointer to the end");
} }
INFO("handle for descriptor %d is %d", fildes, fdDescriptor.FileHandle);
nErrCode = NtWriteFile nErrCode = NtWriteFile
( (
fdDescriptor.FileHandle, fdDescriptor.FileHandle,
@ -51,6 +56,7 @@ ssize_t write(int fildes, const void *buf, size_t nbyte)
if(!NT_SUCCESS(nErrCode)) if(!NT_SUCCESS(nErrCode))
{ {
ERR("NtWriteFile() failed with status 0x%08X", nErrCode);
errno = __status_to_errno(nErrCode); errno = __status_to_errno(nErrCode);
return (0); return (0);
} }