Changeset 10890


Ignore:
Timestamp:
Sep 26, 2008, 2:00:54 PM (11 years ago)
Author:
gb
Message:

More mingw32/stdio.h nonsense.

Actually check in the change which uses overlapped I/O to support
writes to socket-based file descriptors.

Symbol-lookup stuff needs a lock around it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/windows-calls.c

    r10817 r10890  
    2525#include <psapi.h>
    2626#include <dirent.h>
     27#undef __argv
    2728#include <stdio.h>
    2829
     
    291292
    292293  if (hfile == ((HANDLE)-1)) {
    293     return -EBADF;
     294    errno = EBADF;
     295    return -1;
    294296  }
    295297 
     
    343345
    344346ssize_t
    345 lisp_write(int fd, void *buf, unsigned int count)
    346 {
    347   return _write(fd, buf, count);
     347lisp_write(int fd, void *buf, ssize_t count)
     348{
     349  HANDLE hfile;
     350  OVERLAPPED overlapped;
     351  DWORD err, nwritten;
     352
     353  hfile = (HANDLE) _get_osfhandle(fd);
     354
     355  if (hfile == ((HANDLE)-1)) {
     356    errno = EBADF;
     357    return -1;
     358  }
     359
     360  memset(&overlapped,0,sizeof(overlapped));
     361
     362  if (GetFileType(hfile) == FILE_TYPE_DISK) {
     363    overlapped.Offset = SetFilePointer(hfile, 0, &(overlapped.OffsetHigh), FILE_CURRENT);
     364  }
     365
     366  if (WriteFile(hfile, buf, count, &nwritten, &overlapped)) {
     367    return nwritten;
     368  }
     369 
     370  err = GetLastError();
     371  _dosmaperr(err);
     372  return -1;
    348373}
    349374
     
    435460HMODULE *modules = NULL;
    436461DWORD cbmodules = 0;
     462HANDLE find_symbol_lock = 0;
    437463
    438464void *
     
    447473  } else {
    448474    DWORD cbneeded,  have, i;
     475    WaitForSingleObject(find_symbol_lock,INFINITE);
    449476
    450477    if (cbmodules == 0) {
    451478      cbmodules = 16 * sizeof(HANDLE);
    452       modules = LocalAlloc(LPTR, cbmodules);
     479      modules = malloc(cbmodules);
    453480    }
    454481   
     
    459486      }
    460487      cbmodules = cbneeded;
    461       modules = LocalReAlloc(modules,cbmodules,0);
     488      modules = realloc(modules,cbmodules);
    462489    }
    463490    have = cbneeded/sizeof(HANDLE);
     
    467494
    468495      if (addr) {
     496        ReleaseMutex(find_symbol_lock);
    469497        return addr;
    470498      }
    471499    }
     500    ReleaseMutex(find_symbol_lock);
    472501    return NULL;
    473502  }
     
    491520}
    492521
     522
    493523void
    494524init_windows_io()
    495525{
    496 #if 0
    497   int fd;
    498   HANDLE hfile0, hfile1;
    499 
    500   hfile0 = (HANDLE) _get_osfhandle(0);
    501   hfile1 = ReOpenFile(hfile0,GENERIC_READ,FILE_SHARE_READ,FILE_FLAG_OVERLAPPED);
    502   if (hfile1 != ((HANDLE)-1)) {
    503     fd = _open_osfhandle(hfile1,O_RDONLY);
    504     dup2(fd,0);
    505     _close(fd);
    506     SetStdHandle(STD_INPUT_HANDLE,hfile1);
    507     CloseHandle(hfile0);
    508   } else {
    509     wperror("ReOpenFile");
    510   }
    511 
    512   hfile0 = (HANDLE) _get_osfhandle(1);
    513   hfile1 = ReOpenFile(hfile0,GENERIC_WRITE,FILE_SHARE_WRITE,FILE_FLAG_OVERLAPPED);
    514   if (hfile1 != ((HANDLE)-1)) {
    515     fd = _open_osfhandle(hfile1,O_WRONLY);
    516     dup2(fd,1);
    517     _close(fd);
    518     SetStdHandle(STD_OUTPUT_HANDLE,hfile1);
    519     CloseHandle(hfile0);
    520   }
    521 
    522   hfile0 = (HANDLE) _get_osfhandle(2);
    523   hfile1 = ReOpenFile(hfile0,GENERIC_WRITE,FILE_SHARE_WRITE,FILE_FLAG_OVERLAPPED);
    524   if (hfile1 != ((HANDLE)-1)) {
    525     fd = _open_osfhandle(hfile1,O_WRONLY);
    526     dup2(fd,2);
    527     _close(fd);
    528     SetStdHandle(STD_ERROR_HANDLE,hfile1);
    529     CloseHandle(hfile0);
    530   }
    531 #endif 
     526  find_symbol_lock = CreateMutex(NULL,false,NULL);
    532527}
    533528
Note: See TracChangeset for help on using the changeset viewer.