| #define _USE_FILEX |
| #include <unistd.h> |
| #include <stdio.h> |
| #include <windows.h> |
| |
| ssize_t write(int fd, const void *buffer, size_t count) { |
| void *file = (FILEX *)fd->osfhnd; |
| int r, error = 0; |
| |
| if(!count) return 0; |
| //if(file < 0 |
| //if(file == (void *)-1 && (FILEX *)fd->fd < 3) |
| if((FILEX *)fd->osfile & O_APPEND) lseek(fd, 0, FILE_END); |
| |
| if(!WriteFile(file, buffer, count, (unsigned long int)&r, NULL)) error = 1; |
| if(!r) { |
| if(error) return -1; |
| else if(((FILEX *)fd->osfile & 0x40) && *(char *)buffer == 26) return 0; |
| else { |
| SetLastError(ERROR_DISK_FULL); |
| return -1; |
| } |
| } |
| return r; |
| } |