From: Mikko L. <laz...@us...> - 2004-06-12 18:33:40
|
Update of /cvsroot/rtk/rtk/src/core/platform/linux In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25120 Modified Files: File.cpp Log Message: Made some blind changes, w/o even try to compile yet.. Anyway, now there's better change to compile :) Index: File.cpp =================================================================== RCS file: /cvsroot/rtk/rtk/src/core/platform/linux/File.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** File.cpp 11 Jun 2004 22:14:18 -0000 1.1 --- File.cpp 12 Jun 2004 18:33:31 -0000 1.2 *************** *** 89,93 **** uint flags=0; _eos = false; ! _handle = (void*)(fd=fileno(file)); val=fcntl(FD,F_GETFL,0); --- 89,93 ---- uint flags=0; _eos = false; ! _handle = (void*)fileno(file); val=fcntl(FD,F_GETFL,0); *************** *** 171,177 **** --- 171,198 ---- } + #ifdef UNICODE + #define W2A(src, dst) do { \ + int src_len = rstrlen(src); \ + int dst_len = wcstombs(NULL, src, src_len); \ + if(dst_len==-1) break; \ + char *_dst = (char*)alloca(dst_len+1); \ + if(wcstombs(_dst, src, src_len)==-1) break; \ + _dst[dst_len] = '\0'; \ + dst = _dst; \ + } while(0) + #endif + bool File::Open() { const RCHAR *file = _filename.c_str(); + char *afile = NULL; + + #ifdef UNICODE + W2A(file, afile); + if(afile==NULL) return false; + #else + afile = file; + #endif + if (_handle!=INVALID_HANDLE_VALUE) return false; *************** *** 180,186 **** if(_mode & READ) { ! if (_mode & WRITE) open_flags |= O_RDWR; ! else open_flags |= O_RDONLY; ! } else if(_mode & WRITE) open_flags |= O_WRONLY; if(_mode & CREATE) open_flags |= O_CREAT; --- 201,209 ---- if(_mode & READ) { ! if (_mode & WRITE) open_flags |= O_RDWR; ! else open_flags |= O_RDONLY; ! } ! else if(_mode & WRITE) ! open_flags |= O_WRONLY; if(_mode & CREATE) open_flags |= O_CREAT; *************** *** 189,195 **** if(_mode & SYNC) open_flags |= O_SYNC; ! _handle = (void*) open(file, open_flags); ! else if(_mode & LOCKED) if (flock(FD, LOCK_EX|LOCK_NB) == -1) { --- 212,219 ---- if(_mode & SYNC) open_flags |= O_SYNC; ! _handle = (void*) open(afile, open_flags); ! if(_mode & LOCKED) ! { if (flock(FD, LOCK_EX|LOCK_NB) == -1) { *************** *** 197,200 **** --- 221,226 ---- return false; } + } + return IsOpen(); } *************** *** 233,241 **** int read_bytes = 0; ! if((read_bytes=read(_handle, buffer, buffer_len))<0) ! { ! _eos = (read_bytes == 0); ! return read_bytes; ! } _eos = true;//(GetLastError()==ERROR_HANDLE_EOF); --- 259,267 ---- int read_bytes = 0; ! if( (read_bytes=read(_handle, buffer, buffer_len)) >= 0) ! { ! _eos = (read_bytes == 0); ! return read_bytes; ! } _eos = true;//(GetLastError()==ERROR_HANDLE_EOF); *************** *** 251,258 **** _eos = false; ! if((writen_bytes=write(FD, buffer, buffer_len))<0) ! { ! return written_bytes; ! } return -1; --- 277,284 ---- _eos = false; ! if( (writen_bytes=write(FD, buffer, buffer_len)) > 0) ! { ! return written_bytes; ! } return -1; *************** *** 261,268 **** long File::Seek(long pos, IO::SeekMethod method) { - if(_handle==INVALID_HANDLE_VALUE) return -1; if(!CanSeek()) return -1; - int seek_method = SEEK_SET; --- 287,292 ---- *************** *** 272,276 **** default: break; }; ! return (long) lseek(i_handle, pos, seek_method); } --- 296,300 ---- default: break; }; ! return (long) lseek(FD, pos, seek_method); } *************** *** 280,284 **** if(!CanSeek()) return -1; ! return (long) lseek(i_handle, 0, SEEK_CUR); } --- 304,308 ---- if(!CanSeek()) return -1; ! return (long) lseek(FD, 0, SEEK_CUR); } |