bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Few issues for ThreadFile.


From: Federico Montesino Pouzols
Subject: Re: Few issues for ThreadFile.
Date: Thu, 5 Dec 2002 22:24:29 +0100
User-agent: Mutt/1.4i

        Hi, ...

On Wed, Dec 04, 2002 at 01:23:58PM +0300, 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.
> 

        Yes, your suggestion looks better. Fixed in CVS for
ThreadFile, SharedFile and MappedFile.

> 
> 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.

        All these are now fixed.

> 
> 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.
> 

        It would be a useful method, and I do not see any reason to
not include it. Patches are welcome :).

        Bye!

> Sincerely yours,
> Andrew
> 
> 
> 
> 
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp




reply via email to

[Prev in Thread] Current Thread [Next in Thread]