Detecting whether a file is seekable

This tests whether a file can be sought using the lseek system call.

#include <unistd.h>
#include <stdio.h>

#define TYPES 3

int files[TYPES] = {
    STDOUT_FILENO,
    STDIN_FILENO,
    STDERR_FILENO,
};

int main ()
{
    int fileno;
    for (fileno = 0; fileno < TYPES; fileno++) {
        if (lseek (fileno, 0, SEEK_CUR) != -1) {
            printf ("%d is lseek.\n", fileno);
        }
        else {
            printf ("%d is not lseek.\n", fileno);
        }
    }
    return 0;
}

(download)


Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer