bug-commoncpp
[Top][All Lists]
Advanced

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

Few issues for ThreadFile.


From: Andrew L. Shwaika
Subject: Few issues for ThreadFile.
Date: Wed, 04 Dec 2002 13:23:58 +0300

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






reply via email to

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