Next: , Previous: Width of Type, Up: Data Type Measurements


A.5.2 Range of an Integer Type

Suppose you need to store an integer value which can range from zero to one million. Which is the smallest type s used to inquire about the supplementary group IDs of the process. Up to count of these group IDs are stored in the array groups; the return value from the function is the number of group IDs actually stored. If count is smaller than the total number of supplementary group IDs, then getgroups returns a value of -1 and errno is set to EINVAL.

If count is zero, then getgroups just returns the total number of supplementary group IDs. On systems that do not support supplementary groups, this will always be zero.

Here's how to use getgroups to read all the supplementary group IDs:

          gid_t *
          read_all_groups (void)
          {
            int ngroups = getgroups (0, NULL);
            gid_t *groups
              = (gid_t *) xmalloc (ngroups * sizeof (gid_t));
            int val = getgroups (ngroups, groups);
            if (val < 0)
              {
                free (groups);
                return NULL;
              }
            return groups;
          }
     
./usr/share/doc/glibc-doc-reference/html/Reading-Attributes.html0000644000000000000000000001612310470416130023476 0ustar rootroot Reading Attributes - The GNU C Library

Next: , Previous: Attribute Meanings, Up: File Attributes


14.9.2 Reading the Attributes of a File

To examine the attributes of files, use the functions stat, fstat and lstat. They return the attribute information in a struct stat object. All three functions are declared in the header file sys/stat.h.

— Function: int stat (const char *filename, struct stat *buf)

The stat function returns information about the attributes of the file named by filename in the structure pointed to by buf.

If filename is the name of a symbolic link, the attributes you get describe the file that the link points to. If the link points to a nonexistent file name, then stat fails reporting a nonexistent file.

The return value is 0 if the operation is successful, or -1 on failure. In addition to the usual file name errors (see File Name Errors, the following errno error conditions are defined for this function:

ENOENT
The file named by filename doesn't exist.

When the sources are compiled with _FILE_OFFSET_BITS == 64 this function is in fact stat64 since the LFS interface transparently replaces the normal implementation.

— Function: int stat64 (const char *filename, struct stat64 *buf)

This function is similar to stat but it is also able to work on files larger then 2^31 bytes on 32-bit system