Ignore:
Timestamp:
Sep 5, 2001, 2:14:25 PM (24 years ago)
Author:
bird
Message:

Added $Id:$ keyword.

File:
1 edited

Legend:

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

    r4671 r6645  
     1/* $Id: file.c,v 1.3 2001-09-05 12:14:24 bird Exp $ */
    12/*
    23 * CRTDLL file functions
    3  * 
     4 *
    45 * Copyright 1996,1998 Marcus Meissner
    56 * Copyright 1996 Jukka Iivonen
     
    89 *
    910 * Implementation Notes:
    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 
     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
    1213 * FILES and do some other tricks as well (like closeall, _get_osfhandle).
    1314 * For mix and matching with the host libc, processes can use the Win32 HANDLE
     
    128129  else
    129130    while(__CRTDLL_fdstart < __CRTDLL_fdend &&
    130           __CRTDLL_handles[__CRTDLL_fdstart] != INVALID_HANDLE_VALUE)
     131      __CRTDLL_handles[__CRTDLL_fdstart] != INVALID_HANDLE_VALUE)
    131132      __CRTDLL_fdstart++;
    132133
     
    143144{
    144145  TRACE(":fd (%d) allocating FILE*\n",fd);
    145   if (fd < 0 || fd >= __CRTDLL_fdend || 
     146  if (fd < 0 || fd >= __CRTDLL_fdend ||
    146147      __CRTDLL_handles[fd] == INVALID_HANDLE_VALUE)
    147148  {
     
    178179
    179180  TRACE(":handles (%d)(%d)(%d)\n",__CRTDLL_handles[0],
    180         __CRTDLL_handles[1],__CRTDLL_handles[2]);
     181    __CRTDLL_handles[1],__CRTDLL_handles[2]);
    181182
    182183  for (i = 0; i < 3; i++)
     
    195196{
    196197  // return (_access(path, mode));
    197  
     198
    198199  DWORD attr = GetFileAttributesA(filename);
    199200
     
    202203    if (!filename)
    203204    {
    204         /* FIXME: Should GetFileAttributesA() return this? */
     205    /* FIXME: Should GetFileAttributesA() return this? */
    205206      __CRTDLL__set_errno(ERROR_INVALID_DATA);
    206207      return -1;
     
    303304{
    304305  // return (__eof(_fd));
    305  
     306
    306307  DWORD curpos,endpos;
    307308  HANDLE hand = __CRTDLL__fdtoh(fd);
     
    338339{
    339340  // return (_fcloseall());
    340  
     341
    341342  int num_closed = 0, i = 3;
    342343
     
    361362{
    362363  // return (_fdopen(handle, mode));
    363  
     364
    364365  CRTDLL_FILE* file = __CRTDLL__alloc_fp(fd);
    365366
     
    378379{
    379380  // return (_fgetchar());
    380  
     381
    381382  return CRTDLL_fgetc(CRTDLL_stdin);
    382383}
     
    390391 * becomes negative. We ensure that _cnt is always 0 after any read
    391392 * so this function is always called. Our implementation simply calls
    392  * fgetc as all the underlying buffering is handled by Wines 
     393 * fgetc as all the underlying buffering is handled by Wines
    393394 * implementation of the Win32 file I/O calls.
    394395 */
     
    410411{
    411412  // return (_fileno(f));
    412  
     413
    413414  TRACE(":FILE* (%p) fd (%d)\n",file,file->_file);
    414415  return file->_file;
     
    440441{
    441442  // return (_flushall());
    442  
     443
    443444  int num_flushed = 0, i = 3;
    444445
     
    447448    {
    448449      if (CRTDLL__commit(i) == -1)
    449         if (__CRTDLL_files[i])
    450           __CRTDLL_files[i]->_flag |= _IOERR;
     450    if (__CRTDLL_files[i])
     451      __CRTDLL_files[i]->_flag |= _IOERR;
    451452      num_flushed++;
    452453    }
     
    465466{
    466467  // return(_fputchar(c));
    467  
     468
    468469  return CRTDLL_fputc(c, CRTDLL_stdout);
    469470}
     
    484485/*********************************************************************
    485486 *                  _fstat        (CRTDLL.111)
    486  * 
     487 *
    487488 * Get information about an open file.
    488489 */
     
    490491{
    491492  // return (_fstat(file, buf));
    492  
     493
    493494  DWORD dw;
    494495  BY_HANDLE_FILE_INFORMATION hfi;
     
    548549  {
    549550    /* FIXME: I'm not convinced that I should be copying the
    550      * handle here - it may be leaked if the app doesn't 
     551     * handle here - it may be leaked if the app doesn't
    551552     * close it (and the API docs dont say that it should)
    552553     * Not duplicating it means that it can't be inherited
     
    557558     */
    558559    DuplicateHandle(GetCurrentProcess(),hand,GetCurrentProcess(),
    559                     &newhand,0,TRUE,DUPLICATE_SAME_ACCESS );
     560            &newhand,0,TRUE,DUPLICATE_SAME_ACCESS );
    560561  }
    561562  return newhand;
     
    588589{
    589590  // return (_lseek(handle, offset, origin));
    590  
     591
    591592  LONG ret;
    592593  HANDLE hand = __CRTDLL__fdtoh(fd);
     
    777778{
    778779  // return (_setmode(fh, mode));
    779  
     780
    780781  if (mode & _O_TEXT)
    781782    FIXME("fd (%d) mode (%d) TEXT not implemented\n",fd,mode);
     
    790791{
    791792  // return(_stat(s1, n));
    792  
     793
    793794  DWORD dw;
    794795  WIN32_FILE_ATTRIBUTE_DATA hfi;
     
    826827    {
    827828      unsigned int ext = tolower(path[plen-1]) | (tolower(path[plen-2]) << 8)
    828         | (tolower(path[plen-3]) << 16);
     829    | (tolower(path[plen-3]) << 16);
    829830      if (ext == EXE || ext == BAT || ext == CMD || ext == COM)
    830         mode |= CRTDLL_S_IEXEC;
     831    mode |= CRTDLL_S_IEXEC;
    831832    }
    832833  }
     
    843844  buf->st_mtime = buf->st_ctime = dw;
    844845  TRACE("\n%d %d %d %d %d %d\n", buf->st_mode,buf->st_nlink,buf->st_size,
    845         buf->st_atime,buf->st_mtime, buf->st_ctime);
     846    buf->st_atime,buf->st_mtime, buf->st_ctime);
    846847  return 0;
    847848}
     
    856857{
    857858  // return (_tell(i));
    858  
     859
    859860  return CRTDLL__lseek(fd, 0, SEEK_CUR);
    860861}
     
    863864/*********************************************************************
    864865 *                  _tempnam           (CRTDLL.305)
    865  * 
     866 *
    866867 */
    867868LPSTR CDECL CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
    868869{
    869870  // return (_tempnam(dir, prefix));
    870  
     871
    871872  char tmpbuf[MAX_PATH];
    872873
     
    890891{
    891892  // return (_umask(i));
    892  
     893
    893894  INT old_umask = __CRTDLL_umask;
    894895  TRACE("umask (%d)\n",umask);
     
    976977{
    977978  // return (fclose(fp));
    978  
     979
    979980  return CRTDLL__close(file->_file);
    980981}
     
    989990{
    990991  // return (feof(fp));
    991  
     992
    992993  return file->_flag & _IOEOF;
    993994}
     
    10021003{
    10031004  // return (ferror(fp));
    1004  
     1005
    10051006  return file->_flag & _IOERR;
    10061007}
     
    10241025{
    10251026  // return (fgetc(fp));
    1026  
     1027
    10271028  char c;
    10281029  if (CRTDLL__read(file->_file,&c,1) != 1)
     
    10501051{
    10511052  // return (fgets(s, n, fp));
    1052  
     1053
    10531054  int    cc;
    10541055  LPSTR  buf_start = s;
    10551056
    10561057  TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
    1057         file,file->_file,s,size);
     1058    file,file->_file,s,size);
    10581059
    10591060  /* BAD, for the whole WINE process blocks... just done this way to test
     
    10881089{
    10891090  // return (fputs(s, fp));
    1090  
     1091
    10911092  return CRTDLL_fwrite(s,strlen(s),1,file);
    10921093}
     
    10991100{
    11001101    // return (fprintf(file, format, arg));
    1101  
     1102
    11021103    va_list valist;
    11031104    INT res;
     
    11181119{
    11191120  // return (fopen( filename, mode));
    1120  
     1121
    11211122  CRTDLL_FILE* file;
    11221123  INT flags = 0, plus = 0, fd;
     
    11821183{
    11831184  // return (fputc(c, fp));
    1184  
     1185
    11851186  return CRTDLL__write(file->_file, &c, 1) == 1? c : EOF;
    11861187}
     
    11931194{
    11941195  // return (fread(ptr, size, n, fp));
    1195  
     1196
    11961197  DWORD read = CRTDLL__read(file->_file,ptr, size * nmemb);
    11971198  if (read <= 0)
     
    12031204/*********************************************************************
    12041205 *                  freopen    (CRTDLL.379)
    1205  * 
     1206 *
    12061207 */
    12071208CRTDLL_FILE* CDECL CRTDLL_freopen(LPCSTR path, LPCSTR mode,CRTDLL_FILE* file)
    12081209{
    12091210  // return (freopen(filename, mode, fp));
    1210  
     1211
    12111212  CRTDLL_FILE* newfile;
    12121213  INT fd;
     
    12561257{
    12571258  // return (fsetpos(fp, pos));
    1258  
     1259
    12591260  return CRTDLL__lseek(file->_file,*pos,SEEK_SET);
    12601261}
     
    13921393{
    13931394  // return (fseek(file, offset, whence));
    1394  
     1395
    13951396  return CRTDLL__lseek(file->_file,offset,whence);
    13961397}
     
    14031404{
    14041405  // return (ftell(fp));
    1405  
     1406
    14061407  return CRTDLL__tell(file->_file);
    14071408}
     
    14281429{
    14291430  // return (getchar());
    1430  
     1431
    14311432  return CRTDLL_fgetc(CRTDLL_stdin);
    14321433}
     
    14591460     */
    14601461    for(cc = CRTDLL_fgetc(CRTDLL_stdin); cc != EOF && cc != '\n';
    1461         cc = CRTDLL_fgetc(CRTDLL_stdin))
    1462         if(cc != '\r') *buf++ = (char)cc;
     1462    cc = CRTDLL_fgetc(CRTDLL_stdin))
     1463    if(cc != '\r') *buf++ = (char)cc;
    14631464
    14641465    *buf = '\0';
     
    14971498{
    14981499  // return puts( s );
    1499  
     1500
    15001501  return CRTDLL_fputs(s, CRTDLL_stdout);
    15011502}
     
    15111512{
    15121513  // rewind(fp);
    1513  
     1514
    15141515  TRACE(":file (%p) fd (%d)\n",file,file->_file);
    15151516  CRTDLL__lseek(file->_file,0,SEEK_SET);
     
    15241525{
    15251526  // return (remove(file));
    1526  
     1527
    15271528  TRACE(":path (%s)\n",path);
    15281529  if (DeleteFileA(path))
     
    15401541{
    15411542  // return (rename(old, new2));
    1542  
     1543
    15431544  TRACE(":from %s to %s\n",oldpath,newpath);
    15441545  if (MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING))
     
    15561557{
    15571558  // setbuf(fp, buf);
    1558  
     1559
    15591560  TRACE(":file (%p) fd (%d) buf (%p)\n", file, file->_file,buf);
    15601561  if (buf)
     
    15691570 *
    15701571 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
    1571  * 
     1572 *
    15721573 */
    15731574LPSTR CDECL CRTDLL_tmpnam(LPSTR s)
    15741575{
    15751576  // return (tmpnam(s));
    1576  
     1577
    15771578  char tmpbuf[MAX_PATH];
    15781579  char* prefix = "TMP";
     
    15991600{
    16001601  // return (vfprintf(file, format, args));
    1601  
     1602
    16021603  /* FIXME: We should parse the format string, calculate the maximum,
    16031604   * length of each arg, malloc a buffer, print to it, and fwrite that.
Note: See TracChangeset for help on using the changeset viewer.