[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Few issues for ThreadFile.
From: |
David Sugar |
Subject: |
Re: Few issues for ThreadFile. |
Date: |
Thu, 5 Dec 2002 17:01:03 -0500 |
User-agent: |
KMail/1.4.3 |
I am not sure how widely portable ftruncate is, and there is no easy way to
simulate it's behavior on systems that lack it. However, these other
suggestions and changes do look very worthwhile. I think you are right that
it is better to use open rather than creat.
On Wednesday 04 December 2002 05:23, Andrew L. Shwaika wrote:
> Hello,
>
> I've found few issues for ThreadFile class.
>
> ThreadFile::Error ThreadFile::open(const char *path)
> file.cpp:413
> fd = ::open(pathname, O_RDWR);
> if(fd < 0)
> {
> flags.initial = true;
> fd = creat(pathname, (int)attrPrivate);
> }
>
> In this case if file does not exists it will be created by 'creat'
> function, but man pages for 'creat' function says:
> ...
> creat is equivalent to open with flags equal to
> O_CREAT|O_WRONLY|O_TRUNC.
> ...
> So, file will be opened for writing only and any (p)read function fails
> with 'Bad file descriptor' error.
>
> I suppose to change 'creat' to:
> ::open(pathname, O_CREAT|O_RDWR|O_TRUNC, (int)attrPrivate)
>
> It conforms to SVr4, SVID, POSIX, X/OPEN, BSD 4.3 according man pages.
>
> At least this change works fine on RedHat Linux 7.3 kernel 2.4.19.
>
>
> ThreadFile::Error ThreadFile::fetch(caddr_t address, ccxx_size_t len,
> off_t pos)
> file.cpp :493
> io = ::read(fd, fcb->address, fcb->len);
>
> 'io' not declared if HAVE_PREAD_PWRITE not defined, fix:
> int io = ::read(fd, fcb->address, fcb->len);
>
> file.cpp:497
> if((size_t) io == len)
>
> Failed if you try to use 'same size', fix:
> if((size_t) io == fcb->len)
>
>
> ThreadFile::Error ThreadFile::update(caddr_t address, ccxx_size_t len,
> off_t pos)
> file.cpp :554
> io = ::write(fd, fcb->address, fcb->len);
>
> 'io' not declared if HAVE_PREAD_PWRITE not defined, fix:
> int io = ::write(fd, fcb->address, fcb->len);
>
> file.cpp:558
> if((size_t) io == len)
>
> Failed if you try to use 'same size', fix:
> if((size_t) io == fcb->len)
>
>
> ThreadFile::Error ThreadFile::append(caddr_t address, ccxx_size_t len)
> file.cpp:611
> if((size_t) io == len)
>
> Failed if you try to use 'same size', fix:
> if((size_t) io == fcb->len)
>
>
> Exactly the same issues are for SharedFile.
>
> And one question: Is it possible to add method to truncate file to the
> given length?
> For example, on unix systems it can be done by using 'ftruncate( int fd,
> off_t len)' function.
>
> Sincerely yours,
> Andrew
>
>
>
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp