[sword-cvs] swordreader/src/Dll1/winceSword/src unistd.cpp,1.3,1.4

sword@www.crosswire.org sword@www.crosswire.org
Sat, 17 Jan 2004 12:13:16 -0700


Update of /cvs/core/swordreader/src/Dll1/winceSword/src
In directory www:/tmp/cvs-serv25679/src/Dll1/winceSword/src

Modified Files:
	unistd.cpp 
Log Message:
changed fd to be a HANDLE * to circumvent the unsigned nature of HANDLE (which was giving me negative fd values)
I can't believe it, but it seems like it works!

Index: unistd.cpp
===================================================================
RCS file: /cvs/core/swordreader/src/Dll1/winceSword/src/unistd.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- unistd.cpp	17 Jan 2004 07:00:31 -0000	1.3
+++ unistd.cpp	17 Jan 2004 19:13:14 -0000	1.4
@@ -11,7 +11,12 @@
 
 
 int close (int fd) {
-  return fclose((FILE*)fd);
+	if (fd > 0) {
+	  CloseHandle(*(HANDLE *)fd);
+	  delete (HANDLE *)fd;
+	  fd = 0;
+	}
+	return fd;
 }
 
 
@@ -41,12 +46,13 @@
 
 //  if (mode & O_BINARY)
 
-  HANDLE result = CreateFile(strtowstr(winPath), access, share, NULL, create, FILE_ATTRIBUTE_NORMAL, NULL);
+  HANDLE *result = new HANDLE;
+  *result = CreateFile(strtowstr(winPath), access, share, NULL, create, FILE_ATTRIBUTE_NORMAL, NULL);
 
 
 //  int result=(int)fopen(winPath, cmode);
 
-  if (result == INVALID_HANDLE_VALUE) {
+  if (*result == INVALID_HANDLE_VALUE) {
 	  WCHAR buf[100];
 	  mbstowcs(buf,"file: ",6);
 	  mbstowcs(&buf[6],winPath,100);
@@ -54,10 +60,11 @@
 	  DWORD errorNr=GetLastError();
 	  _itow(errorNr,&buf[wcslen(buf)],10);
 	  MessageBox(0,buf,L"Unable to open:",MB_OK|MB_ICONERROR);
-	  result = (HANDLE)-1;
+	  delete result;
+	  result = (HANDLE *)-1;
   }
   if (((int)result > -1) && (mode & O_APPEND)) {
-	  SetFilePointer(result, 0, 0, FILE_END);
+	  SetFilePointer(*result, 0, 0, FILE_END);
   }
 
   return (int)result;
@@ -71,7 +78,11 @@
 
 int read(int fd, void *buf, size_t count) {
 	DWORD readCount;
-	ReadFile((HANDLE)fd, buf, (DWORD)count, &readCount, NULL);
+//__try {
+	ReadFile(*(HANDLE *)fd, buf, (DWORD)count, &readCount, NULL);
+//} __except (EXCEPTION_EXECUTE_HANDLER) {
+//	return 0;
+//}
 	return (int)readCount;
 
 }
@@ -79,7 +90,7 @@
 
 int write(int fd, const void *buf, size_t count) {
 	DWORD writtenCount;
-	WriteFile((HANDLE)fd, buf, (DWORD)count, &writtenCount, NULL);
+	WriteFile(*(HANDLE *)fd, buf, (DWORD)count, &writtenCount, NULL);
 	return writtenCount;
 }
 
@@ -102,7 +113,7 @@
 	}
 
 
-	off_t retVal = SetFilePointer((HANDLE)fildes, (LONG)offset, 0, wWence);
+	off_t retVal = SetFilePointer(*(HANDLE *)fildes, (LONG)offset, 0, wWence);
 
 	if (retVal == 0xFFFFFFFF)
 		retVal = -1;