Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]

#include <stat.h>
Link against: libc.lib

S_ISUID

Interface status: externallyDefinedApi

S_ISUID 0004000

Description

set user id on execution

[Top]


S_ISGID

Interface status: externallyDefinedApi

S_ISGID 0002000

Description

set group id on execution

[Top]


S_IRWXU

Interface status: externallyDefinedApi

S_IRWXU 0000700

Description

RWX mask for owner

[Top]


S_IRUSR

Interface status: externallyDefinedApi

S_IRUSR 0000400

Description

R for owner

[Top]


S_IWUSR

Interface status: externallyDefinedApi

S_IWUSR 0000200

Description

W for owner

[Top]


S_IXUSR

Interface status: externallyDefinedApi

S_IXUSR 0000100

Description

X for owner

[Top]


S_IRWXG

Interface status: externallyDefinedApi

S_IRWXG 0000070

Description

RWX mask for group

[Top]


S_IRGRP

Interface status: externallyDefinedApi

S_IRGRP 0000040

Description

R for group

[Top]


S_IWGRP

Interface status: externallyDefinedApi

S_IWGRP 0000020

Description

W for group

[Top]


S_IXGRP

Interface status: externallyDefinedApi

S_IXGRP 0000010

Description

X for group

[Top]


S_IRWXO

Interface status: externallyDefinedApi

S_IRWXO 0000007

Description

RWX mask for other

[Top]


S_IROTH

Interface status: externallyDefinedApi

S_IROTH 0000004

Description

R for other

[Top]


S_IWOTH

Interface status: externallyDefinedApi

S_IWOTH 0000002

Description

W for other

[Top]


S_IXOTH

Interface status: externallyDefinedApi

S_IXOTH 0000001

Description

X for other

[Top]


S_IFMT

Interface status: externallyDefinedApi

S_IFMT 0170000

Description

type of file mask

[Top]


S_IFIFO

Interface status: externallyDefinedApi

S_IFIFO 0010000

Description

named pipe (fifo)

[Top]


S_IFCHR

Interface status: externallyDefinedApi

S_IFCHR 0020000

Description

character special

[Top]


S_IFDIR

Interface status: externallyDefinedApi

S_IFDIR 0040000

Description

directory

[Top]


S_IFBLK

Interface status: externallyDefinedApi

S_IFBLK 0060000

Description

block special

[Top]


S_IFREG

Interface status: externallyDefinedApi

S_IFREG 0100000

Description

regular

[Top]


S_IFLNK

Interface status: externallyDefinedApi

S_IFLNK 0120000

Description

symbolic link

[Top]


S_ISVTX

Interface status: externallyDefinedApi

S_ISVTX 0001000

Description

save swapped text even after use

[Top]


S_ISDIR

Interface status: externallyDefinedApi

S_ISDIR (m) (((m) & 0170000) == 0040000)

Description

directory.

Parameters

m

[Top]


S_ISCHR

Interface status: externallyDefinedApi

S_ISCHR (m) (((m) & 0170000) == 0020000)

Description

char special.

Parameters

m

[Top]


S_ISBLK

Interface status: externallyDefinedApi

S_ISBLK (m) (((m) & 0170000) == 0060000)

Description

block special

Parameters

m

[Top]


S_ISREG

Interface status: externallyDefinedApi

S_ISREG (m) (((m) & 0170000) == 0100000)

Description

regular file

Parameters

m

[Top]


S_ISFIFO

Interface status: externallyDefinedApi

S_ISFIFO (m) (((m) & 0170000) == 0010000)

Description

fifo or socket

Parameters

m

[Top]


S_ISLNK

Interface status: externallyDefinedApi

S_ISLNK (m) (((m) & 0170000) == 0120000)

Description

symbolic link

Parameters

m

[Top]


Typedef blksize_t

Interface status: externallyDefinedApi

typedef __blksize_t blksize_t;

Description

Used for block sizes.

[Top]


Typedef blkcnt_t

Interface status: externallyDefinedApi

typedef __blkcnt_t blkcnt_t;

Description

Used for file block counts.

[Top]


Typedef dev_t

Interface status: externallyDefinedApi

typedef __dev_t dev_t;

Description

device number or struct cdev

[Top]


Typedef fflags_t

typedef __fflags_t fflags_t;

Description

file flags

[Top]


Typedef ino_t

Interface status: externallyDefinedApi

typedef __ino_t ino_t;

Description

Used for file serial numbers.

[Top]


Typedef nlink_t

Interface status: externallyDefinedApi

typedef __nlink_t nlink_t;

Description

Used for link counts.

[Top]


chmod(const char *,mode_t)

Interface status: externallyDefinedApi

IMPORT_C int chmod(const char *, mode_t);

Description

  #include < sys/stat.h > :

The file permission bits of the file named specified by _path or referenced by the file descriptor fd are changed to _mode. The chmod system call verifies that the process owner (user) either owns the file specified by _path (or fd ), or is the super-user. The chmod system call follows symbolic links to operate on the target of the link rather than the link itself.

The lchmod system call is similar to chmod but does not follow symbolic links.

A mode is created from ored permission bit masks defined in #include <sys/stat.h> :

#define S_IRWXU 0000700    // RWX mask for owner
#define S_IRUSR 0000400    // R for owner 
#define S_IWUSR 0000200    // W for owner 
#define S_IXUSR 0000100    // X for owner 
#define S_IRWXG 0000070    // RWX mask for group
#define S_IRGRP 0000040    // R for group
#define S_IWGRP 0000020    // W for group
#define S_IXGRP 0000010    // X for group
#define S_IRWXO 0000007    // RWX mask for other
#define S_IROTH 0000004    // R for other
#define S_IWOTH 0000002    // W for other
#define S_IXOTH 0000001    // X for other
#define S_ISUID 0004000    // set user id on execution
#define S_ISGID 0002000    // set group id on execution
#ifndef __BSD_VISIBLE
#define S_ISTXT 0001000    // sticky bit
#endif

Notes :

Sticky bit and set id on execution are not supported.

Permission values for group and others are ignored as there is no concept of group and others on the Symbian OS. The flag bits S_IXUSR, S_IXGRP & S_IXOTH are ignored as execute permissions on a file are meaningless on Symbian OS.

An attempt to change file permission to write-only changes the file permission to read-write.

Either or both of S_IRUSR or S_IWUSR bits must be set in the _mode argument, else chmod fails with EINVAL.

Permissions for directories are ignored.

000 mode is treated as invalid mode as Symbian OS cannot have entries with both read and write permissions absent.

Examples:

/*Detailed description: This test code demonstartes usage of chmod system call, it
 changes mode of file Example.txt in the current working directory to read-only.
 Preconditions: Example.txt file should be present in the current working directory.
 */
int main()
{
  if(chmod("Example.txt" , 0444) < 0 )  
  {
     printf("change mode of file Example.txt failed");
     return -1;
  }
  printf("Chmod system call successful");
  return 0;
}

Output

Chmod system call successful
/* Detailed description : This sample code demonstrates the usage of fchmod system call, this code
 changes mode of file Example.txt using fchmod system call.
 */
# 98 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 99 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 100 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
int main()
{
 int fd = 0;
 fd = open("Example.txt" ,  0x0200  |  0x0002  , 0666);
 if(fd < 0 )   {
    printf("Failed to open file Example.txt");
    return -1;
 }
 if(fchmod(fd , 0444) < 0 )  {
    printf("fchmod failed to change mode of file Example.txt");
    return -1;
 }
 printf("Fchmod call changed mode of Example.txt");
 return 0;
}

Output

Fchmod call changed mode of Example.txt

Limitations:

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

Parameters

const char *

mode_tmode_t

Note: This description also covers the following functions - fchmod(int,mode_t)fchmod(int,mode_t) lchmod()

Return value

int

Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

See also:

[Top]


fchmod(int,mode_t)

Interface status: externallyDefinedApi

IMPORT_C int fchmod(int, mode_t);

Description

Parameters

int

mode_tmode_t

Refer to chmod(const char *,mode_t)chmod(const char *,mode_t) for the documentation

Return value

int

See also:

[Top]


fstat(int,struct stat *)

Interface status: externallyDefinedApi

IMPORT_C int fstat(int, struct stat *);

Description

Parameters

int

struct statstat *

Refer to stat(const char *,struct stat *)stat(const char *,struct stat *) for the documentation

Return value

int

See also:

[Top]


lstat(const char *,struct stat *)

Interface status: externallyDefinedApi

IMPORT_C int lstat(const char *, struct stat *);

Description

Parameters

const char *

struct statstat *

Refer to stat(const char *,struct stat *)stat(const char *,struct stat *) for the documentation

Return value

int

See also:

[Top]


__xstat(int,const char *,struct stat *)

IMPORT_C int __xstat(int, const char *file, struct stat *buf);

Description

Parameters

int

const char *file

struct statstat *buf

Refer to stat(const char *,struct stat *)stat(const char *,struct stat *) for the documentation

Return value

int

See also:

[Top]


__lxstat(int,const char *,struct stat *)

IMPORT_C int __lxstat(int, const char *file, struct stat *buf);

Description

Parameters

int

const char *file

struct statstat *buf

Refer to stat(const char *,struct stat *)stat(const char *,struct stat *) for the documentation

Return value

int

See also:

[Top]


mkdir(const char *,mode_t)

Interface status: externallyDefinedApi

IMPORT_C int mkdir(const char *, mode_t);

Description

The directory _path is created with the access permissions specified by _mode.

Notes:

_mode values and access permissions are ignored in Symbian OS.

The default working directory of a process is initialized to C: \private\U ID (UID of the calling application) and any data written into this directory persists between phone resets.

The parent directory's time stamp is not updated when a new child is created.

The newly created directory will be empty (i.e. it doesn't have "." and ".." entries)

Examples:

/* Detailed description : This test code demonstrates usage of mkdir systemcall,
 it creates function a  directory Example in current working directory.
 */
int main()
{
  if(mkdir("Example" , 0666) < 0 )  
  {
      printf("Directory creation failed");
      return -1;
  }
  printf("Directory Example created");
  return 0;
}

Output

Directory Example created

Limitations:

The path parameter in mkdir(const char *,mode_t)mkdir(const char *,mode_t) should not exceed 256 characters in length.

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

The path given to mkdir(const char *,mode_t)mkdir(const char *,mode_t) should be complete. Attempting to create a directory my calling mkdir("logs",0400|0200|0100) will pass on emulator but fails on h/w because the cwd is taken as c: on emulator and z: on h/w. Since Z drive is a rom on h/w, mkdir(const char *,mode_t)mkdir(const char *,mode_t) fails by setting errno to 13 on hardware.

Parameters

const char *

mode_tmode_t

Return value

int

The mkdir(const char *,mode_t)mkdir(const char *,mode_t) function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

See also:

[Top]


mkfifo(const char *,mode_t)

Interface status: externallyDefinedApi

IMPORT_C int mkfifo(const char *, mode_t);

Description

The mkfifo system call creates a new FIFO(First In First Out) file with name path. The access permissions are specified by mode and restricted by the umask of the calling process. With the current implementation, the use of umask has no effect.

The FIFO's owner ID and group ID are set to root.

Please note that running stat on a FIFO file does not provide modification time information (it provides the creation time). Use fstat on the fd to retrieve the last modified time.

Examples:

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

int main(void)
{
    char *pathname = "C:\XXX";
    mode_t mode = 0666;
    if (mkfifo(pathname, mode) == -1) {
        printf("mkfifo() failed");
    }
    return 0;
}

Limitations:

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

Parameters

const char *

mode_tmode_t

Return value

int

The mkfifo function returns the value 0 if successful; otherwise the value -1 is returned and errno is set to indicate the error.

See also:

[Top]


stat(const char *,struct stat *)

Interface status: externallyDefinedApi

IMPORT_C int stat(const char *, struct stat *);

Description

 st_dev The numeric ID of the device containing the file.
 st_ino The file's inode number.
 st_nlink
  The number of hard links to the file.
 st_atime Time when file data last accessed.
 Changed by the .Xr utimes 2, read and readv system calls.
 st_mtime Time when file data last modified.
 Changed by the mkdir, mkfifo, mknod, utimes, write and writev system calls.
 st_ctime Time when file status was last changed (inode data modification).
 Changed by the chmod, chown, creat, link, mkdir, mkfifo, mknod, rename, rmdir, symlink, truncate, unlink, utimes, write and writev system calls.
 st_birthtime
  Time when the inode was created.
 st_size The file size in bytes.
 st_blksize
  The optimal I/O block size for the file.
 st_blocks The actual number of blocks allocated for the file in 512-byte units.
 As short symbolic links are stored in the inode, this number may
 be zero.
 st_uid The user ID of the file's owner.
 st_gid The group ID of the file.
 st_mode
  Status of the file (see below).
 Test for a block special file.
 Test for a character special file.
 Test for a directory.
 Test for a pipe or FIFO special file.
 Test for a symbolic link. NOTE: Inode structure is not supported by Symbian OS and hence link count updation is not possible.
 Check for symbolic link would always fail because of this reason.
 Test for a regular file.
 Test for a socket.
 Test for a whiteout.

The stat system call obtains information about the file pointed to by path. Read, write or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.

The lstat system call is like stat except in the case where the named file is a symbolic link, in which case lstat returns information about the link, while stat returns information about the file the link references.

The fstat system call obtains the same information about an open file known by the file descriptor fd.

The __xstat and __lxstat system calls are exactly similar to stat and lstat functionality.

The sb argument is a pointer to a stat structure as defined by #include <sys/stat.h> and into which information is placed concerning the file.

The fields of struct stat related to the file system are as follows:

st_dev The numeric ID of the device containing the file. 
st_ino The file's inode number. 
st_nlink  The number of hard links to the file.

The st_dev and st_ino fields together identify the file uniquely within the system.

The time-related fields of struct stat are as follows:

st_atime TimeTime when file data last accessed. Changed by the .Xr utimes 2, read and readv system calls. st_mtime TimeTime when file data last modified. Changed by the mkdir, mkfifo, mknod, utimes, write and writev system calls. st_ctime TimeTime when file status was last changed (inode data modification). Changed by the chmod, chown, creat, link, mkdir, mkfifo, mknod, rename, rmdir, symlink, truncate, unlink, utimes, write and writev system calls. st_birthtime TimeTime when the inode was created.

If _POSIX_SOURCE is not defined, the time-related fields are defined as:

#ifndef _POSIX_SOURCE
#define st_atime st_atimespec.tv_sec
#define st_mtime st_mtimespec.tv_sec
#define st_ctime st_ctimespec.tv_sec
#endif

The size-related fields of the struct stat are as follows: st_size The file size in bytes. st_blksize The optimal I/O block size for the file. st_blocks The actual number of blocks allocated for the file in 512-byte units.

As short symbolic links are stored in the inode, this number may be zero.

The access-related fields of struct stat are as follows: st_uid The user ID of the file's owner. st_gid The group ID of the file. st_mode Status of the file (see below).

The status information word st_mode has the following bits:

#define S_IFMT   0170000  // type of file
#define S_IFIFO  0010000  // named pipe (fifo) 
#define S_IFCHR  0020000  // character special 
#define S_IFDIR  0040000  // directory 
#define S_IFBLK  0060000  // block special 
#define S_IFREG  0100000  // regular 
#define S_IFLNK  0120000  // symbolic link 
#define S_IFSOCK 0140000  // socket 
#define S_IFWHT  0160000  // whiteout 
#define S_ISUID  0004000  // set user id on execution 
#define S_ISGID  0002000  // set group id on execution 
#define S_ISVTX  0001000  // save swapped text even after use 
#define S_IRUSR  0000400  // read permission, owner 
#define S_IWUSR  0000200  // write permission, owner 
#define S_IXUSR  0000100  // execute/search permission, owner 

For a list of access modes, see #include <sys/stat.h> access and chmod The following macros are available to test whether a st_mode value passed in the m argument corresponds to a file of the specified type: S_ISBLK (m); Test for a block special file. S_ISCHR (m); Test for a character special file. S_ISDIR (m); Test for a directory. S_ISFIFO (m); Test for a pipe or FIFO special file. S_ISLNK (m); Test for a symbolic link. NOTE: Inode structure is not supported by Symbian OS and hence link count updation is not possible. Check for symbolic link would always fail because of this reason. S_ISREG (m); Test for a regular file. S_ISSOCK (m); Test for a socket. S_ISWHT (m); Test for a whiteout.

The macros evaluate to a non-zero value if the test is true or to the value 0 if the test is false.

Note: To obtain correct timestamps of FIFOs use fstat instead of stat call.

Examples:

/* Detailed description: Sample usage of stat system call
 Preconditions: Example.txt file should be present in working directory 
 */
# 509 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 510 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 511 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 512 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
int main()
{
  struct stat buf;
   if(stat("Example.txt"  , &buf;) < 0 )
   {
      printf("Failed to stat Example.txt");
      return -1;
   }
   printf("Stat system call succeeded");
   return 0;
 }
/*
 Detailed description: Sample usage of fstat system call

 */
# 528 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 529 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 530 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
# 531 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/stat.dosc" 2
int main()
{
  struct stat buf;
   int fd = open("Example.txt" ,  0x0000  |  0x0200   , 0666);
   if(fstat(fd  , &buf;) < 0 ) 
   {
      printf("Failed to stat Example.txt");
      return -1;
   }
   printf("Stat system call succeeded");
   close(fd);
   return 0;
 }

Output

Stat system call succeeded

Output

Stat system call succeeded

Limitations:

The path parameters of the stat(const char *,struct stat *)stat(const char *,struct stat *) and lstat(const char *,struct stat *)lstat(const char *,struct stat *) functions should not exceed 256 characters each in length.

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

Parameters

const char *

struct statstat *

Note: This description also covers the following functions - lstat(const char *,struct stat *)lstat(const char *,struct stat *) fstat __xstat(int,const char *,struct stat *)__xstat(int,const char *,struct stat *) __lxstat(int,const char *,struct stat *)__lxstat(int,const char *,struct stat *)

Return value

int

Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

See also:

[Top]


umask(mode_t)

Interface status: externallyDefinedApi

IMPORT_C mode_t umask(mode_t);

Description

This function is build supported but not available functionally. Symbian OS does not support multiple users and groups

Parameters

mode_tmode_t

Return value

mode_tmode_t

This function always returns MASK_RWUSR.