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