memset (&fl, '\0', sizeof (struct flock));
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
- result = fcntl (file_fd, F_SETLKW, &fl);
+ fcntl (file_fd, F_SETLKW, &fl);
/* Read the next entry. */
nbytes = read (file_fd, &last_entry, sizeof (struct utmp));
/* And unlock the file. */
fl.l_type = F_UNLCK;
- result = fcntl (file_fd, F_SETLKW, &fl);
+ fcntl (file_fd, F_SETLKW, &fl);
if (nbytes != sizeof (struct utmp))
{
static struct utmp *
pututline_file (const struct utmp *data)
{
+ struct flock fl; /* Information struct for locking. */
struct utmp buffer;
struct utmp *pbuf;
int found;
/* Something went wrong. */
return NULL;
+ if (file_fd == INT_MIN)
+ /* The file is closed. Open it again. */
+ setutent_file (0);
+
/* Find the correct place to insert the data. */
if (file_offset > 0)
found = 0;
found = internal_getutid_r (data, &buffer);
/* Try to lock the file. */
- if (flock (file_fd, LOCK_EX | LOCK_NB) < 0 && errno != ENOSYS)
- {
- /* Oh, oh. The file is already locked. Wait a bit and try again. */
- sleep (1);
-
- /* This time we ignore the error. */
- (void) flock (file_fd, LOCK_EX | LOCK_NB);
- }
+ memset (&fl, '\0', sizeof (struct flock));
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fcntl (file_fd, F_SETLKW, &fl);
if (found < 0)
{
if (lseek (file_fd, 0, SEEK_END) < 0)
{
- (void) flock (file_fd, LOCK_UN);
- return NULL;
+ pbuf = NULL;
+ goto unlock_return;
}
}
}
pbuf = (struct utmp *) data;
}
+ unlock_return:
/* And unlock the file. */
- (void) flock (file_fd, LOCK_UN);
+ fl.l_type = F_UNLCK;
+ fcntl (file_fd, F_SETLKW, &fl);
return pbuf;
}
@item -
The number is not padded at all.
+
+@item 0
+The number is padded with zeros even if the format spefies padding
+with spaces.
@end table
The default action is to pad the number with zeros to keep it a constant
width. Numbers that do not have a range indicated below are never
padded, since there is no natural width for them.
-An optional modifier can follow the optional flag. The modifiers, which
-are POSIX.2 extensions, are:
+Following the flag an optional specification of the width is possible.
+This is specified in decimal notation. If the natural size of the
+output is of the field has less than the specifed number of character,
+the result is written right adjusted and space padded to the given
+size.
+
+An optional modifier can follow the optional flag and width
+specification. The modifiers, which are POSIX.2 extensions, are:
@table @code
@item E
applies only to numeric format specifiers.
@end table
-A modifier is ignored if no alternate representation is available.
+If the format supports the modifier but no alternate representation
+is available, it is ignored.
The conversion specifier ends with a format specifier taken from the
following list. The whole @samp{%} sequence is replaced in the output
If @var{s} is a null pointer, @code{strftime} does not actually write
anything, but instead returns the number of characters it would have written.
+According to POSIX.1 every call to @code{strftime} implies a call to
+@code{tzset}. So the contents of the environment variable @code{TZ}
+is examined before any output is produced.
+
For an example of @code{strftime}, see @ref{Time Functions Example}.
@end deftypefun