63
No value is returned.
Description:
The
tzset()
function uses the value of the environment variables
TZ
to set the time
conversion information used by
localtime(),ctime(),strftime()
, and
mktime()
. If
TZ
is absent from the environment, a default timezone is used. This is most
often Coordinate
d Universal Time (UTC).
The external variable
tzname[0]
is set to a pointer to the name of the standard timezone and
the external variable
tzname[1]
is set to a pointer to the name of the daylight savings
timezone.
Reference:
P 8.3.2.1
Conversion:
This function is not supported in BSD.
Notes:
P
age 492
umask()
—Sets a file creation mask.
Synopsis:
#include <sys/types.h>
#include <sys/stat.h>
mode_t umask(mode_t cmask);
Arguments:
cmask
Permission bits to turn off in created files.
Returns:
The previous mask.
Description:
The
umask()
function sets the process file creation mask to
cmask
. The file creation mask is
used during
open(),creat(),mkdir()
, and
mkfifo()
calls to turn off permission bits
in the mode argument. Bit positions that are set in
cmask
are cleared in the mod
e of the
created file.
The file creation mask is inherited across
fork()
and
exec()
calls. This makes it possible
to alter the default permission bits of created files.
60
Reference:
P 5.3.3.1
Conversion:
BSD and SVR1-3 return int and use int for
cmask
.
Notes:
The
cmask
argument should have only permission bits set. All other bits should be zero.
P
age 493
uname()
—Gets system name.
Synopsis:
#include <sys/utsname.h>
int uname(struct utsname *name);
Arguments:
name
Pointer to a structure to hold the result.
Returns:
Zero on success and
-1
on failure.
If an error occurs, a code is stored in
errno
to identify the error.
Description:
The
uname()
function provides information about the system you are using. The information
is fairly minimal. The
name
argument is a pointer to a
struct
utsname
to be filled in by
the
uname()
call.
The
struct
utsname
is defined in the header file
<sys/utsname.h>
as a set of
null-terminated character arrays. The structure contains the following members:
Member Name
Description
sysname
Name of this operating system.
nodename
Name of this node within a network. Note: There is no guarantee that this name can be
used for anything.
release
Current release level of this implementation.
version
Current version l
evel of this release. While POSIX provides the release level and
version, it never defines them.
54
machine
Name of the hardware type the system is running on.
As with most POSIX structures, these members may be in any order and there may be other
members present.
Reference:
P 4.4.1.1
P
age 494
Conversion:
This function is not supported in BSD.
Notes:
The strings returned by
uname()
are useful for messages; they are not useful for much else.
P
age 495
ungetc()
—Pushes a character back onto a stream.
Synopsis:
#include <stdio.h>
int ungetc(int c, FILE *stream);
Arguments:
c
Character to push back.
stream
Pointer to the file being read.
Returns:
c
on success and
EOF
on failure.
Description:
Push the character
c
, converted to
unsigned
char
, back onto
stream
. The pushed-back
characters will be returned in reverse order. The file associated with
stream
is unchanged.
Only one push-back is guaranteed. If
ungetc()
is called too many times it may fa
il.
If the value of
c
is EOF, the operation fails without doing anything to
stream
.
The end-of-file indicator is cleared. The value of the file position indicator after the
pushed-back characters are read is the same as before they were pushed back.
41
Reference:
C 4.9.7.11
Notes:
It is possible to put back a different character from the one that was read.
P
age 496
unlink()
—Removes a directory entry.
Synopsis:
#include <unistd.h>
int unlink(const char *path);
Arguments:
path
Pointer to path name of file to delete.
Returns:
Zero on success and
-1
on failure.
If an error occurs, a code is stored in
errno
to identify the error.
Errors:
EACCES, EBUSY, ENAMETOOLONG, ENOENT, ENOTDIR, EPERM, EROFS
Description:
The
unlink()
function removes the link named by
path
and decrements the link count of
the file referenced by the link. When the link count goes to zero and no process has the file
open, the space occupied by the file is freed and the file is no longer acce
ssible.
Reference:
P 5.5.1.1
Conversion:
Add to the list of headers:
#include <unistd.h>
Notes:
See
remove()
for an alternate name for this function.
64
P
age 497
utime()
—Sets file access and modification times.
Synopsis:
#include <sys/types.h>
#include <utime.h>
int utime(const char *path, const struct utimbuf *times);
Arguments:
path
Pointer to name of file to update.
times
Pointer to a structure with the new access and modification times; if
NULL
, the current
time is used.
Returns:
Zero on success and
-1
on failure.
If an error occurs, a code is stored in
errno
to identify the error.
Errors:
EACCES, ENAMETOOLONG, ENOENT, ENOTDIR, EPERM, EROFS
Description:
The
utime()
function sets the access and modification times for the file named by
path
.
The
tm
argument is either
NULL
or a pointer to a
utimbuf
structure. If the tm argument is
NULL, the access and modification times are set to the current time.
If the
tm
argument is not
NULL
, it is assumed to be a pointer to a
utimbuf
structure. This
contains the following members:
actime
Access time.
modtime
Modification time.
Both members have type
time_t
.
Reference:
P 5.6.6.1
P
age 498
Conversion:
SVR1-3 did not use
<utime.h>
and stated that the structure
utimbuf
must be defined as:
61
struct utimbuf {
time_t actime;
time t modtime;
};
BSD did not use a
struct
but an array of
2 time_t
elements.
Notes:
This is one of the few functions where a structure is used as an argument and there is no
function to initialize the structure. It is a good idea to zero out the entire structure before using
it.
P
age 499
va_arg()
—Gets the next argument.
Synopsis:
#include <stdarg.h>
type va_arg(va_list ap, type);
Arguments:
ap
Same variable initialized by
va_start()
.
type
Type of the return.
Returns:
The next argument.
Description:
The
va_arg()
macro expands to an expression that has the type and value of the next
argument in the call. The parameter
ap
must be the same as the
va_list ap
initialized by
va_start()
. Each call to
va_arg()
updates
ap
so that the next call will access the
next
argument. The argument must have a type of
type
.
The
va_arg()
macro must not be called after the last argument is accessed.
Example:
#include <stdarg.h>
/*
* Function to return the sum of a variable list of args
*/
int vsum(int count, ...)
{
int sum = O; /* The sum */
int i;
/* Temp */
57
va_list ap; /* Arg pointer */
va_start(ap,count); /* Setup for va_arg() */
for (i=O; i<count; i++)
{
sum += va_arg(ap, int);
}
va_end(ap);
return(sum);
}
Reference:
C 4.8.1.2
P
age 500
Conversion:
BSD used the header
<varargs.h>
instead of
<stdarg.h>
.
Notes:
Use with
va_start()
and
va_end()
.
This function is required by Standard C and is not part of the POSIX standard.
P
age 501
va_end()
—Ends variable argument list.
Synopsis:
#include <stdarg.h>
void va_end(va_list ap);
Arguments:
ap
Same variable initialized by
va_start()
.
Returns:
No value is returned.
Description:
The
va_end()
macro facilitates a normal return from a function with a variable argument
list. The
va_end(
) macro must be used after a
va_start()
and before returning from the
function. Programs that call
va_start()
without calling
va_end()
are not maximall
y
portable.
Reference:
65
C 4.8.1.3
Conversion:
BSD used the header
<varargs.h>
instead of
<stdarg. h>
.
Notes:
In most implementations,
va_end()
does not do anything. However, if it is omitted the
program is non-conforming and not maximally portable.
See
va_arg()
for an example.
This function is required by Standard C and is not part of the POSIX standard.
P
age 502
va_start()
—Starts a variable argument list.
Synopsis:
#include <stdarg.h>
void va_start(va_list ap, parmN);
Arguments:
ap
Pointer to be initialized.
parmN
Rightmost parameter in the function definition (the one just before the
...
).
Returns:
No value is returned. The pointer
ap
is set for use by
va_arg()
.
Description:
The
va_start()
macro is invoked before using the
va_arg()
macro. The parameter
parmN
is the argument just before the (
...
) in the function prototype. The
parmN
argument
may not be an array, may not have
register
storage class, may not be a function, or may
not
be a type incompatible with default argument promotions.
Reference:
C 4.8.1.1
Conversion:
BSD used the header
<varargs.h>
instead of
<stdarg.h>
.
Notes:
See
va_arg()
for an example.
Documents you may be interested
Documents you may be interested