extending file with zeros (fclear() on aix) - SGI

This is a discussion on extending file with zeros (fclear() on aix) - SGI ; I'm converting an AIX app to IRIX. AIX had a function called fclear(fd,x) that extended a file by x bytes and wrote zeros in the extended portion. Does IRIX have an equivalent function? In order to be self supporting for ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: extending file with zeros (fclear() on aix)

  1. extending file with zeros (fclear() on aix)

    I'm converting an AIX app to IRIX. AIX had a function called fclear(fd,x)
    that extended a file by x bytes and wrote zeros in the extended portion.

    Does IRIX have an equivalent function?

    In order to be self supporting for the next time I need a function to do
    whatever...Is there an automated way to search the documentation to find an
    API that does "extend file" or "zero fill file"?

    thanks

    Duane

  2. Re: extending file with zeros (fclear() on aix)

    On Fri, 5 Mar 2004 noone@nowhere.com wrote:

    > I'm converting an AIX app to IRIX. AIX had a function called fclear(fd,x)
    > that extended a file by x bytes and wrote zeros in the extended portion.
    >
    > Does IRIX have an equivalent function?


    Odd, I just ran across the equivalent for the first time today. Lucky
    timing for you.

    See fcntl(2).

    You'll want to use the fcntl(fd, F_FREESP, ...) command. I don't know
    what the AIX fclear() semantics are exactly, or if you've described
    them accurately, but this should be a close approximation on IRIX:

    int
    fclear(int fd, off_t growsize) {
    struct flock fl;
    fl.l_whence = SEEK_END;
    fl.l_start = growsize;
    fl.l_len = 0;
    return fcntl(fd, F_FREESP, &fl);
    }

    You might need to tweek this somewhat depending on what the exact
    semantics of the AIX function are (i.e. return value, if it grows
    from the end of the file or the current file position, if it
    truncates everything after the grown portion, etc). But it should
    be enough to get you started.

    > In order to be self supporting for the next time I need a function to do
    > whatever...Is there an automated way to search the documentation to find an
    > API that does "extend file" or "zero fill file"?


    Did you try searching at http://techpubs.sgi.com/?

    Hope that helps,
    Brent Casavant

    --
    Brent Casavant bcasavan@sgi.com Forget bright-eyed and
    Operating System Engineer http://www.sgi.com/ bushy-tailed; I'm red-
    Silicon Graphics, Inc. 44.8562N 93.1355W 860F eyed and bushy-haired.

  3. Re: extending file with zeros (fclear() on aix)

    On 2004-03-05, noone@nowhere.com wrote:
    > I'm converting an AIX app to IRIX. AIX had a function called fclear(fd,x)
    > that extended a file by x bytes and wrote zeros in the extended portion.
    >
    > Does IRIX have an equivalent function?


    Do you really need it?
    Seeking beyon the end of a file creates a so called 'sparse' file. That
    is, you can seek beyond the end whenever you like without the need to
    pregrow the file (unless you effectively need to allocate that space).

    The region between the end and the new position is actually zeroed when
    the space if effectively allocated.

    > In order to be self supporting for the next time I need a function to do
    > whatever...Is there an automated way to search the documentation to find an
    > API that does "extend file" or "zero fill file"?
    >
    > thanks


    As pointed out, http://techpubs.sgi.com or look at infosearch(1) for a
    local solution.

    --
    __/ __, wave++ "Yuri D'Elia" http://www.yuv.info/
    / \__/ \ HPC and Engineering: bringing BITs to life!
    \__/ \_ WARNING: the email address is fake.

+ Reply to Thread