lstat(), lstat64()

Updated: April 19, 2023

Get information about a file or directory


#include <sys/stat.h>

int lstat( const char* path, 
           struct stat* buf );

int lstat64( const char* path, 
             struct stat64* buf );


The path of the file or directory that you want information about.
A pointer to a struct stat or struct stat64 buffer where the function can store the information.



Use the -l c option to qcc to link against this library. This library is usually included automatically.


The lstat() and lstat64() functions obtain information about the file or directory referenced in path. This information is placed in the structure located at the address indicated by buf. The lstat64() function is a large-file support version of lstat().

Note: In QNX Neutrino 6.6 or later, the large-file support functions and data types appear in the name space only if you define _LARGEFILE64_SOURCE when you compile your code. For more information, see Classification in What's in a Function Description?

The results of the lstat() function are the same as the results of stat() when used on a file that isn't a symbolic link. If the file is a symbolic link, lstat() returns information about the symbolic link, while stat() continues to resolve the pathname using the contents of the symbolic link, and returns information about the resulting file.


An error occurred (errno is set).


See stat() for details.


 * Iterate through a list of files, and report 
 * for each if it is a symbolic link
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

int main( int argc, char **argv )
    int ecode = 0;
    int n;
    struct stat sbuf;

    for( n = 1; n < argc; ++n ) {
      if( lstat( argv[n], &sbuf ) == -1 ) {
        perror( argv[n] );

      } else if( S_ISLNK( sbuf.st_mode ) ) {
        printf( "%s is a symbolic link\n", argv[n] );

      } else {
        printf( "%s is not a symbolic link\n", argv[n] );
    return( ecode );


lstat() is POSIX 1003.1; lstat64() is Large-file support

Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes