/[svn]/ircd-hybrid-7.2/src/fileio.c
ViewVC logotype

Diff of /ircd-hybrid-7.2/src/fileio.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1000 by lusky, Sun Oct 2 21:05:51 2005 UTC revision 1001 by michael, Sat Aug 29 22:44:44 2009 UTC
# Line 41  int Line 41  int
41  file_open(fde_t *F, const char *filename, int mode, int fmode)  file_open(fde_t *F, const char *filename, int mode, int fmode)
42  {  {
43    int fd;    int fd;
 #ifdef _WIN32  
   DWORD dwDesiredAccess = 0;  
44    
   switch (mode & ~(O_CREAT | O_TRUNC | O_APPEND))  
   {  
     case O_RDONLY:  
       dwDesiredAccess = GENERIC_READ;  
       break;  
     case O_WRONLY:  
       dwDesiredAccess = GENERIC_WRITE;  
       break;  
     case O_RDWR:  
       dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;  
   }  
   
   fd = (int) CreateFile(  
     filename,  
     dwDesiredAccess,  
     FILE_SHARE_READ | ((dwDesiredAccess & GENERIC_WRITE) ? 0:FILE_SHARE_WRITE),  
     NULL,  
     ((mode & O_CREAT) == 0) ? OPEN_EXISTING :  
     ((mode & O_TRUNC) ? CREATE_ALWAYS : OPEN_ALWAYS),  
     FILE_ATTRIBUTE_NORMAL,  
     NULL  
   );  
   
   if (fd == (int)INVALID_HANDLE_VALUE)  
   {  
     errno = GetLastError();  
     return -1;  
   }  
   
   if ((mode & O_APPEND))  
     SetFilePointer((HANDLE)fd, 0, NULL, FILE_END);  
 #else  
45    if (number_fd == hard_fdlimit)    if (number_fd == hard_fdlimit)
46    {    {
47      errno = ENFILE;      errno = ENFILE;
# Line 84  file_open(fde_t *F, const char *filename Line 50  file_open(fde_t *F, const char *filename
50    
51    if ((fd = open(filename, mode, fmode)) < 0)    if ((fd = open(filename, mode, fmode)) < 0)
52      return -1;      return -1;
 #endif  
53    
54    fd_open(F, fd, 0, filename);    fd_open(F, fd, 0, filename);
55    return 0;    return 0;
# Line 141  fbrewind(FBFILE *fb) Line 106  fbrewind(FBFILE *fb)
106    fb->flags = 0;    fb->flags = 0;
107    fb->pbptr = NULL;    fb->pbptr = NULL;
108    
 #ifdef _WIN32  
   SetFilePointer((HANDLE)fb->F.fd, 0, NULL, FILE_BEGIN);  
 #else  
109    lseek(fb->F.fd, 0, SEEK_SET);    lseek(fb->F.fd, 0, SEEK_SET);
 #endif  
110    return 0;    return 0;
111  }  }
112    
# Line 166  fbfill(FBFILE *fb) Line 127  fbfill(FBFILE *fb)
127    if (fb->flags)    if (fb->flags)
128      return -1;      return -1;
129    
 #ifdef _WIN32  
   if (!ReadFile((HANDLE)fb->F.fd, fb->buf, BUFSIZ, (LPDWORD)&n, NULL))  
     n = -1;  
 #else  
130    n = read(fb->F.fd, fb->buf, BUFSIZ);    n = read(fb->F.fd, fb->buf, BUFSIZ);
 #endif  
131    
132    if (n > 0)    if (n > 0)
133    {    {
# Line 268  fbputs(const char *str, FBFILE *fb, size Line 224  fbputs(const char *str, FBFILE *fb, size
224    if (0 == fb->flags)    if (0 == fb->flags)
225    {    {
226      assert(strlen(str) == nbytes);      assert(strlen(str) == nbytes);
 #ifdef _WIN32  
     if (!WriteFile((HANDLE)fb->F.fd, str, nbytes, (LPDWORD)&n, NULL))  
       n = -1;  
 #else  
227      n = write(fb->F.fd, str, nbytes);      n = write(fb->F.fd, str, nbytes);
228  #endif  
229      if (n == -1)      if (n == -1)
230        fb->flags |= FB_FAIL;        fb->flags |= FB_FAIL;
231    }    }

Legend:
Removed from v.1000  
changed lines
  Added in v.1001

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28