Changeset 6712 for trunk/src/crtdll/file.c
- Timestamp:
- Sep 15, 2001, 11:47:44 AM (24 years ago)
- 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 $ */2 1 /* 3 2 * CRTDLL file functions 4 * 3 * 5 4 * Copyright 1996,1998 Marcus Meissner 6 5 * Copyright 1996 Jukka Iivonen … … 9 8 * 10 9 * 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 13 12 * FILES and do some other tricks as well (like closeall, _get_osfhandle). 14 13 * For mix and matching with the host libc, processes can use the Win32 HANDLE … … 129 128 else 130 129 while(__CRTDLL_fdstart < __CRTDLL_fdend && 131 130 __CRTDLL_handles[__CRTDLL_fdstart] != INVALID_HANDLE_VALUE) 132 131 __CRTDLL_fdstart++; 133 132 … … 144 143 { 145 144 TRACE(":fd (%d) allocating FILE*\n",fd); 146 if (fd < 0 || fd >= __CRTDLL_fdend || 145 if (fd < 0 || fd >= __CRTDLL_fdend || 147 146 __CRTDLL_handles[fd] == INVALID_HANDLE_VALUE) 148 147 { … … 179 178 180 179 TRACE(":handles (%d)(%d)(%d)\n",__CRTDLL_handles[0], 181 180 __CRTDLL_handles[1],__CRTDLL_handles[2]); 182 181 183 182 for (i = 0; i < 3; i++) … … 196 195 { 197 196 // return (_access(path, mode)); 198 197 199 198 DWORD attr = GetFileAttributesA(filename); 200 199 … … 203 202 if (!filename) 204 203 { 205 204 /* FIXME: Should GetFileAttributesA() return this? */ 206 205 __CRTDLL__set_errno(ERROR_INVALID_DATA); 207 206 return -1; … … 304 303 { 305 304 // return (__eof(_fd)); 306 305 307 306 DWORD curpos,endpos; 308 307 HANDLE hand = __CRTDLL__fdtoh(fd); … … 339 338 { 340 339 // return (_fcloseall()); 341 340 342 341 int num_closed = 0, i = 3; 343 342 … … 362 361 { 363 362 // return (_fdopen(handle, mode)); 364 363 365 364 CRTDLL_FILE* file = __CRTDLL__alloc_fp(fd); 366 365 … … 379 378 { 380 379 // return (_fgetchar()); 381 380 382 381 return CRTDLL_fgetc(CRTDLL_stdin); 383 382 } … … 391 390 * becomes negative. We ensure that _cnt is always 0 after any read 392 391 * 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 394 393 * implementation of the Win32 file I/O calls. 395 394 */ … … 411 410 { 412 411 // return (_fileno(f)); 413 412 414 413 TRACE(":FILE* (%p) fd (%d)\n",file,file->_file); 415 414 return file->_file; … … 441 440 { 442 441 // return (_flushall()); 443 442 444 443 int num_flushed = 0, i = 3; 445 444 … … 448 447 { 449 448 if (CRTDLL__commit(i) == -1) 450 451 449 if (__CRTDLL_files[i]) 450 __CRTDLL_files[i]->_flag |= _IOERR; 452 451 num_flushed++; 453 452 } … … 466 465 { 467 466 // return(_fputchar(c)); 468 467 469 468 return CRTDLL_fputc(c, CRTDLL_stdout); 470 469 } … … 485 484 /********************************************************************* 486 485 * _fstat (CRTDLL.111) 487 * 486 * 488 487 * Get information about an open file. 489 488 */ … … 491 490 { 492 491 // return (_fstat(file, buf)); 493 492 494 493 DWORD dw; 495 494 BY_HANDLE_FILE_INFORMATION hfi; … … 549 548 { 550 549 /* 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 552 551 * close it (and the API docs dont say that it should) 553 552 * Not duplicating it means that it can't be inherited … … 558 557 */ 559 558 DuplicateHandle(GetCurrentProcess(),hand,GetCurrentProcess(), 560 559 &newhand,0,TRUE,DUPLICATE_SAME_ACCESS ); 561 560 } 562 561 return newhand; … … 589 588 { 590 589 // return (_lseek(handle, offset, origin)); 591 590 592 591 LONG ret; 593 592 HANDLE hand = __CRTDLL__fdtoh(fd); … … 778 777 { 779 778 // return (_setmode(fh, mode)); 780 779 781 780 if (mode & _O_TEXT) 782 781 FIXME("fd (%d) mode (%d) TEXT not implemented\n",fd,mode); … … 791 790 { 792 791 // return(_stat(s1, n)); 793 792 794 793 DWORD dw; 795 794 WIN32_FILE_ATTRIBUTE_DATA hfi; … … 827 826 { 828 827 unsigned int ext = tolower(path[plen-1]) | (tolower(path[plen-2]) << 8) 829 828 | (tolower(path[plen-3]) << 16); 830 829 if (ext == EXE || ext == BAT || ext == CMD || ext == COM) 831 830 mode |= CRTDLL_S_IEXEC; 832 831 } 833 832 } … … 844 843 buf->st_mtime = buf->st_ctime = dw; 845 844 TRACE("\n%d %d %d %d %d %d\n", buf->st_mode,buf->st_nlink,buf->st_size, 846 845 buf->st_atime,buf->st_mtime, buf->st_ctime); 847 846 return 0; 848 847 } … … 857 856 { 858 857 // return (_tell(i)); 859 858 860 859 return CRTDLL__lseek(fd, 0, SEEK_CUR); 861 860 } … … 864 863 /********************************************************************* 865 864 * _tempnam (CRTDLL.305) 866 * 865 * 867 866 */ 868 867 LPSTR CDECL CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix) 869 868 { 870 869 // return (_tempnam(dir, prefix)); 871 870 872 871 char tmpbuf[MAX_PATH]; 873 872 … … 891 890 { 892 891 // return (_umask(i)); 893 892 894 893 INT old_umask = __CRTDLL_umask; 895 894 TRACE("umask (%d)\n",umask); … … 977 976 { 978 977 // return (fclose(fp)); 979 978 980 979 return CRTDLL__close(file->_file); 981 980 } … … 990 989 { 991 990 // return (feof(fp)); 992 991 993 992 return file->_flag & _IOEOF; 994 993 } … … 1003 1002 { 1004 1003 // return (ferror(fp)); 1005 1004 1006 1005 return file->_flag & _IOERR; 1007 1006 } … … 1025 1024 { 1026 1025 // return (fgetc(fp)); 1027 1026 1028 1027 char c; 1029 1028 if (CRTDLL__read(file->_file,&c,1) != 1) … … 1051 1050 { 1052 1051 // return (fgets(s, n, fp)); 1053 1052 1054 1053 int cc; 1055 1054 LPSTR buf_start = s; 1056 1055 1057 1056 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n", 1058 1057 file,file->_file,s,size); 1059 1058 1060 1059 /* BAD, for the whole WINE process blocks... just done this way to test … … 1089 1088 { 1090 1089 // return (fputs(s, fp)); 1091 1090 1092 1091 return CRTDLL_fwrite(s,strlen(s),1,file); 1093 1092 } … … 1100 1099 { 1101 1100 // return (fprintf(file, format, arg)); 1102 1101 1103 1102 va_list valist; 1104 1103 INT res; … … 1119 1118 { 1120 1119 // return (fopen( filename, mode)); 1121 1120 1122 1121 CRTDLL_FILE* file; 1123 1122 INT flags = 0, plus = 0, fd; … … 1183 1182 { 1184 1183 // return (fputc(c, fp)); 1185 1184 1186 1185 return CRTDLL__write(file->_file, &c, 1) == 1? c : EOF; 1187 1186 } … … 1194 1193 { 1195 1194 // return (fread(ptr, size, n, fp)); 1196 1195 1197 1196 DWORD read = CRTDLL__read(file->_file,ptr, size * nmemb); 1198 1197 if (read <= 0) … … 1204 1203 /********************************************************************* 1205 1204 * freopen (CRTDLL.379) 1206 * 1205 * 1207 1206 */ 1208 1207 CRTDLL_FILE* CDECL CRTDLL_freopen(LPCSTR path, LPCSTR mode,CRTDLL_FILE* file) 1209 1208 { 1210 1209 // return (freopen(filename, mode, fp)); 1211 1210 1212 1211 CRTDLL_FILE* newfile; 1213 1212 INT fd; … … 1257 1256 { 1258 1257 // return (fsetpos(fp, pos)); 1259 1258 1260 1259 return CRTDLL__lseek(file->_file,*pos,SEEK_SET); 1261 1260 } … … 1393 1392 { 1394 1393 // return (fseek(file, offset, whence)); 1395 1394 1396 1395 return CRTDLL__lseek(file->_file,offset,whence); 1397 1396 } … … 1404 1403 { 1405 1404 // return (ftell(fp)); 1406 1405 1407 1406 return CRTDLL__tell(file->_file); 1408 1407 } … … 1429 1428 { 1430 1429 // return (getchar()); 1431 1430 1432 1431 return CRTDLL_fgetc(CRTDLL_stdin); 1433 1432 } … … 1460 1459 */ 1461 1460 for(cc = CRTDLL_fgetc(CRTDLL_stdin); cc != EOF && cc != '\n'; 1462 1463 1461 cc = CRTDLL_fgetc(CRTDLL_stdin)) 1462 if(cc != '\r') *buf++ = (char)cc; 1464 1463 1465 1464 *buf = '\0'; … … 1498 1497 { 1499 1498 // return puts( s ); 1500 1499 1501 1500 return CRTDLL_fputs(s, CRTDLL_stdout); 1502 1501 } … … 1512 1511 { 1513 1512 // rewind(fp); 1514 1513 1515 1514 TRACE(":file (%p) fd (%d)\n",file,file->_file); 1516 1515 CRTDLL__lseek(file->_file,0,SEEK_SET); … … 1525 1524 { 1526 1525 // return (remove(file)); 1527 1526 1528 1527 TRACE(":path (%s)\n",path); 1529 1528 if (DeleteFileA(path)) … … 1541 1540 { 1542 1541 // return (rename(old, new2)); 1543 1542 1544 1543 TRACE(":from %s to %s\n",oldpath,newpath); 1545 1544 if (MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) … … 1557 1556 { 1558 1557 // setbuf(fp, buf); 1559 1558 1560 1559 TRACE(":file (%p) fd (%d) buf (%p)\n", file, file->_file,buf); 1561 1560 if (buf) … … 1570 1569 * 1571 1570 * lcclnk from lcc-win32 relies on a terminating dot in the name returned 1572 * 1571 * 1573 1572 */ 1574 1573 LPSTR CDECL CRTDLL_tmpnam(LPSTR s) 1575 1574 { 1576 1575 // return (tmpnam(s)); 1577 1576 1578 1577 char tmpbuf[MAX_PATH]; 1579 1578 char* prefix = "TMP"; … … 1600 1599 { 1601 1600 // return (vfprintf(file, format, args)); 1602 1601 1603 1602 /* FIXME: We should parse the format string, calculate the maximum, 1604 1603 * length of each arg, malloc a buffer, print to it, and fwrite that.
Note:
See TracChangeset
for help on using the changeset viewer.