Ignore:
Timestamp:
Sep 15, 2001, 11:47:44 AM (24 years ago)
Author:
sandervl
Message:

restored old version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/crtdll/file.c

    r6645 r6712  
    1 /* $Id: file.c,v 1.3 2001-09-05 12:14:24 bird Exp $ */
    21/*
    32 * CRTDLL file functions
    4  *
     3 * 
    54 * Copyright 1996,1998 Marcus Meissner
    65 * Copyright 1996 Jukka Iivonen
     
    98 *
    109 * Implementation Notes:
    11  * Mapping is performed between FILE*, fd and HANDLE's. This allows us to
    12  * implement all calls using the Win32 API, support remapping fd's to
     10 * Mapping is performed between FILE*, fd and HANDLE's. This allows us to 
     11 * implement all calls using the Win32 API, support remapping fd's to 
    1312 * FILES and do some other tricks as well (like closeall, _get_osfhandle).
    1413 * For mix and matching with the host libc, processes can use the Win32 HANDLE
     
    129128  else
    130129    while(__CRTDLL_fdstart < __CRTDLL_fdend &&
    131       __CRTDLL_handles[__CRTDLL_fdstart] != INVALID_HANDLE_VALUE)
     130          __CRTDLL_handles[__CRTDLL_fdstart] != INVALID_HANDLE_VALUE)
    132131      __CRTDLL_fdstart++;
    133132
     
    144143{
    145144  TRACE(":fd (%d) allocating FILE*\n",fd);
    146   if (fd < 0 || fd >= __CRTDLL_fdend ||
     145  if (fd < 0 || fd >= __CRTDLL_fdend || 
    147146      __CRTDLL_handles[fd] == INVALID_HANDLE_VALUE)
    148147  {
     
    179178
    180179  TRACE(":handles (%d)(%d)(%d)\n",__CRTDLL_handles[0],
    181     __CRTDLL_handles[1],__CRTDLL_handles[2]);
     180        __CRTDLL_handles[1],__CRTDLL_handles[2]);
    182181
    183182  for (i = 0; i < 3; i++)
     
    196195{
    197196  // return (_access(path, mode));
    198 
     197 
    199198  DWORD attr = GetFileAttributesA(filename);
    200199
     
    203202    if (!filename)
    204203    {
    205     /* FIXME: Should GetFileAttributesA() return this? */
     204        /* FIXME: Should GetFileAttributesA() return this? */
    206205      __CRTDLL__set_errno(ERROR_INVALID_DATA);
    207206      return -1;
     
    304303{
    305304  // return (__eof(_fd));
    306 
     305 
    307306  DWORD curpos,endpos;
    308307  HANDLE hand = __CRTDLL__fdtoh(fd);
     
    339338{
    340339  // return (_fcloseall());
    341 
     340 
    342341  int num_closed = 0, i = 3;
    343342
     
    362361{
    363362  // return (_fdopen(handle, mode));
    364 
     363 
    365364  CRTDLL_FILE* file = __CRTDLL__alloc_fp(fd);
    366365
     
    379378{
    380379  // return (_fgetchar());
    381 
     380 
    382381  return CRTDLL_fgetc(CRTDLL_stdin);
    383382}
     
    391390 * becomes negative. We ensure that _cnt is always 0 after any read
    392391 * so this function is always called. Our implementation simply calls
    393  * fgetc as all the underlying buffering is handled by Wines
     392 * fgetc as all the underlying buffering is handled by Wines 
    394393 * implementation of the Win32 file I/O calls.
    395394 */
     
    411410{
    412411  // return (_fileno(f));
    413 
     412 
    414413  TRACE(":FILE* (%p) fd (%d)\n",file,file->_file);
    415414  return file->_file;
     
    441440{
    442441  // return (_flushall());
    443 
     442 
    444443  int num_flushed = 0, i = 3;
    445444
     
    448447    {
    449448      if (CRTDLL__commit(i) == -1)
    450     if (__CRTDLL_files[i])
    451       __CRTDLL_files[i]->_flag |= _IOERR;
     449        if (__CRTDLL_files[i])
     450          __CRTDLL_files[i]->_flag |= _IOERR;
    452451      num_flushed++;
    453452    }
     
    466465{
    467466  // return(_fputchar(c));
    468 
     467 
    469468  return CRTDLL_fputc(c, CRTDLL_stdout);
    470469}
     
    485484/*********************************************************************
    486485 *                  _fstat        (CRTDLL.111)
    487  *
     486 * 
    488487 * Get information about an open file.
    489488 */
     
    491490{
    492491  // return (_fstat(file, buf));
    493 
     492 
    494493  DWORD dw;
    495494  BY_HANDLE_FILE_INFORMATION hfi;
     
    549548  {
    550549    /* FIXME: I'm not convinced that I should be copying the
    551      * handle here - it may be leaked if the app doesn't
     550     * handle here - it may be leaked if the app doesn't 
    552551     * close it (and the API docs dont say that it should)
    553552     * Not duplicating it means that it can't be inherited
     
    558557     */
    559558    DuplicateHandle(GetCurrentProcess(),hand,GetCurrentProcess(),
    560             &newhand,0,TRUE,DUPLICATE_SAME_ACCESS );
     559                    &newhand,0,TRUE,DUPLICATE_SAME_ACCESS );
    561560  }
    562561  return newhand;
     
    589588{
    590589  // return (_lseek(handle, offset, origin));
    591 
     590 
    592591  LONG ret;
    593592  HANDLE hand = __CRTDLL__fdtoh(fd);
     
    778777{
    779778  // return (_setmode(fh, mode));
    780 
     779 
    781780  if (mode & _O_TEXT)
    782781    FIXME("fd (%d) mode (%d) TEXT not implemented\n",fd,mode);
     
    791790{
    792791  // return(_stat(s1, n));
    793 
     792 
    794793  DWORD dw;
    795794  WIN32_FILE_ATTRIBUTE_DATA hfi;
     
    827826    {
    828827      unsigned int ext = tolower(path[plen-1]) | (tolower(path[plen-2]) << 8)
    829     | (tolower(path[plen-3]) << 16);
     828        | (tolower(path[plen-3]) << 16);
    830829      if (ext == EXE || ext == BAT || ext == CMD || ext == COM)
    831     mode |= CRTDLL_S_IEXEC;
     830        mode |= CRTDLL_S_IEXEC;
    832831    }
    833832  }
     
    844843  buf->st_mtime = buf->st_ctime = dw;
    845844  TRACE("\n%d %d %d %d %d %d\n", buf->st_mode,buf->st_nlink,buf->st_size,
    846     buf->st_atime,buf->st_mtime, buf->st_ctime);
     845        buf->st_atime,buf->st_mtime, buf->st_ctime);
    847846  return 0;
    848847}
     
    857856{
    858857  // return (_tell(i));
    859 
     858 
    860859  return CRTDLL__lseek(fd, 0, SEEK_CUR);
    861860}
     
    864863/*********************************************************************
    865864 *                  _tempnam           (CRTDLL.305)
    866  *
     865 * 
    867866 */
    868867LPSTR CDECL CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
    869868{
    870869  // return (_tempnam(dir, prefix));
    871 
     870 
    872871  char tmpbuf[MAX_PATH];
    873872
     
    891890{
    892891  // return (_umask(i));
    893 
     892 
    894893  INT old_umask = __CRTDLL_umask;
    895894  TRACE("umask (%d)\n",umask);
     
    977976{
    978977  // return (fclose(fp));
    979 
     978 
    980979  return CRTDLL__close(file->_file);
    981980}
     
    990989{
    991990  // return (feof(fp));
    992 
     991 
    993992  return file->_flag & _IOEOF;
    994993}
     
    10031002{
    10041003  // return (ferror(fp));
    1005 
     1004 
    10061005  return file->_flag & _IOERR;
    10071006}
     
    10251024{
    10261025  // return (fgetc(fp));
    1027 
     1026 
    10281027  char c;
    10291028  if (CRTDLL__read(file->_file,&c,1) != 1)
     
    10511050{
    10521051  // return (fgets(s, n, fp));
    1053 
     1052 
    10541053  int    cc;
    10551054  LPSTR  buf_start = s;
    10561055
    10571056  TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
    1058     file,file->_file,s,size);
     1057        file,file->_file,s,size);
    10591058
    10601059  /* BAD, for the whole WINE process blocks... just done this way to test
     
    10891088{
    10901089  // return (fputs(s, fp));
    1091 
     1090 
    10921091  return CRTDLL_fwrite(s,strlen(s),1,file);
    10931092}
     
    11001099{
    11011100    // return (fprintf(file, format, arg));
    1102 
     1101 
    11031102    va_list valist;
    11041103    INT res;
     
    11191118{
    11201119  // return (fopen( filename, mode));
    1121 
     1120 
    11221121  CRTDLL_FILE* file;
    11231122  INT flags = 0, plus = 0, fd;
     
    11831182{
    11841183  // return (fputc(c, fp));
    1185 
     1184 
    11861185  return CRTDLL__write(file->_file, &c, 1) == 1? c : EOF;
    11871186}
     
    11941193{
    11951194  // return (fread(ptr, size, n, fp));
    1196 
     1195 
    11971196  DWORD read = CRTDLL__read(file->_file,ptr, size * nmemb);
    11981197  if (read <= 0)
     
    12041203/*********************************************************************
    12051204 *                  freopen    (CRTDLL.379)
    1206  *
     1205 * 
    12071206 */
    12081207CRTDLL_FILE* CDECL CRTDLL_freopen(LPCSTR path, LPCSTR mode,CRTDLL_FILE* file)
    12091208{
    12101209  // return (freopen(filename, mode, fp));
    1211 
     1210 
    12121211  CRTDLL_FILE* newfile;
    12131212  INT fd;
     
    12571256{
    12581257  // return (fsetpos(fp, pos));
    1259 
     1258 
    12601259  return CRTDLL__lseek(file->_file,*pos,SEEK_SET);
    12611260}
     
    13931392{
    13941393  // return (fseek(file, offset, whence));
    1395 
     1394 
    13961395  return CRTDLL__lseek(file->_file,offset,whence);
    13971396}
     
    14041403{
    14051404  // return (ftell(fp));
    1406 
     1405 
    14071406  return CRTDLL__tell(file->_file);
    14081407}
     
    14291428{
    14301429  // return (getchar());
    1431 
     1430 
    14321431  return CRTDLL_fgetc(CRTDLL_stdin);
    14331432}
     
    14601459     */
    14611460    for(cc = CRTDLL_fgetc(CRTDLL_stdin); cc != EOF && cc != '\n';
    1462     cc = CRTDLL_fgetc(CRTDLL_stdin))
    1463     if(cc != '\r') *buf++ = (char)cc;
     1461        cc = CRTDLL_fgetc(CRTDLL_stdin))
     1462        if(cc != '\r') *buf++ = (char)cc;
    14641463
    14651464    *buf = '\0';
     
    14981497{
    14991498  // return puts( s );
    1500 
     1499 
    15011500  return CRTDLL_fputs(s, CRTDLL_stdout);
    15021501}
     
    15121511{
    15131512  // rewind(fp);
    1514 
     1513 
    15151514  TRACE(":file (%p) fd (%d)\n",file,file->_file);
    15161515  CRTDLL__lseek(file->_file,0,SEEK_SET);
     
    15251524{
    15261525  // return (remove(file));
    1527 
     1526 
    15281527  TRACE(":path (%s)\n",path);
    15291528  if (DeleteFileA(path))
     
    15411540{
    15421541  // return (rename(old, new2));
    1543 
     1542 
    15441543  TRACE(":from %s to %s\n",oldpath,newpath);
    15451544  if (MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING))
     
    15571556{
    15581557  // setbuf(fp, buf);
    1559 
     1558 
    15601559  TRACE(":file (%p) fd (%d) buf (%p)\n", file, file->_file,buf);
    15611560  if (buf)
     
    15701569 *
    15711570 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
    1572  *
     1571 * 
    15731572 */
    15741573LPSTR CDECL CRTDLL_tmpnam(LPSTR s)
    15751574{
    15761575  // return (tmpnam(s));
    1577 
     1576 
    15781577  char tmpbuf[MAX_PATH];
    15791578  char* prefix = "TMP";
     
    16001599{
    16011600  // return (vfprintf(file, format, args));
    1602 
     1601 
    16031602  /* FIXME: We should parse the format string, calculate the maximum,
    16041603   * length of each arg, malloc a buffer, print to it, and fwrite that.
Note: See TracChangeset for help on using the changeset viewer.