connect(2) connect(2) opendir/readdir(3) opendir/readdir(3) connect − initiate a connection on a socket

connect(2) connect(2) opendir/readdir(3) opendir/readdir(3) connect − initiate a connection on a socket
connect(2)
connect(2)
NAME
opendir/readdir(3)
opendir/readdir(3)
NAME
connect − initiate a connection on a socket
opendir − open a directory / readdir − read a directory
SYNOPSIS
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <dirent.h>
int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen);
DIR *opendir(const char *name);
DESCRIPTION
The file descriptor sockfd must refer to a socket. If the socket is of type SOCK_DGRAM then the
serv_addr address is the address to which datagrams are sent by default, and the only address from which
datagrams are received. If the socket is of type SOCK_STREAM or SOCK_SEQPACKET, this call
attempts to make a connection to another socket. The other socket is specified by serv_addr, which is an
address (of length addrlen) in the communications space of the socket. Each communications space interprets the serv_addr parameter in its own way.
Generally, connection-based protocol sockets may successfully connect only once; connectionless protocol
sockets may use connect multiple times to change their association. Connectionless sockets may dissolve
the association by connecting to an address with the sa_family member of sockaddr set to AF_UNSPEC.
RETURN VALUE
struct dirent *readdir(DIR *dir);
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
DESCRIPTION opendir
The opendir() function opens a directory stream corresponding to the directory name, and returns a pointer
to the directory stream. The stream is positioned at the first entry in the directory.
RETURN VALUE
The opendir() function returns a pointer to the directory stream or NULL if an error occurred.
DESCRIPTION readdir
If the connection or binding succeeds, zero is returned. On error, −1 is returned, and errno is set appropriately.
ERRORS
The readdir() function returns a pointer to a dirent structure representing the next directory entry in the
directory stream pointed to by dir. It returns NULL on reaching the end-of-file or if an error occurred.
DESCRIPTION readdir_r
The following are general socket errors only. There may be other domain-specific error codes.
The readdir_r() function initializes the structure referenced by entry and stores a pointer to this structure
in result. On successful return, the pointer returned at *result will have the same value as the argument
entry. Upon reaching the end of the directory stream, this pointer will have the value NULL.
EBADF
The file descriptor is not a valid index in the descriptor table.
EFAULT
The socket structure address is outside the user’s address space.
The data returned by readdir() is overwritten by subsequent calls to readdir() for the same directory
stream.
ENOTSOCK
The file descriptor is not associated with a socket.
The dirent structure is defined as follows:
EISCONN
The socket is already connected.
struct dirent {
long
d_ino;
/* inode number */
off_t
d_off;
/* offset to the next dirent */
unsigned short d_reclen;
/* length of this record */
unsigned char d_type;
/* type of file */
char
d_name[256]; /* filename */
};
ECONNREFUSED
No one listening on the remote address.
ENETUNREACH
Network is unreachable.
EADDRINUSE
Local address is already in use.
RETURN VALUE
The readdir() function returns a pointer to a dirent structure, or NULL if an error occurs or end-of-file is
reached.
EAFNOSUPPORT
The passed address didn’t have the correct address family in its sa_family field.
readdir_r() returns 0 if successful or an error number to indicate failure.
EACCES, EPERM
The user tried to connect to a broadcast address without having the socket broadcast flag enabled
or the connection request failed because of a local firewall rule.
SEE ALSO
ERRORS
EACCES
Permission denied.
ENOENT
Directory does not exist, or name is an empty string.
accept(2), bind(2), listen(2), socket(2), getsockname(2)
ENOTDIR
name is not a directory.
SOS1-Klausur Manual-Auszug
2006-03-23
1
SOS1-Klausur Manual-Auszug
2006-03-23
1
fopen/fdopen(3)
fopen/fdopen(3)
NAME
fileno(3)
fileno(3)
NAME
fopen, fdopen − stream open functions
clearerr, feof, ferror, fileno − check and reset stream status
SYNOPSIS
SYNOPSIS
#include <stdio.h>
#include <stdio.h>
FILE *fopen(const char * path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
void clearerr(FILE *stream);
int feof(FILE *stream);
int ferror(FILE *stream);
int fileno(FILE *stream);
DESCRIPTION
The fopen function opens the file whose name is the string pointed to by path and associates a stream with
it.
The argument mode points to a string beginning with one of the following sequences (Additional characters
may follow these sequences.):
DESCRIPTION
The function clearerr clears the end-of-file and error indicators for the stream pointed to by stream.
The function feof tests the end-of-file indicator for the stream pointed to by stream, returning non-zero if it
is set. The end-of-file indicator can only be cleared by the function clearerr.
r
Open text file for reading. The stream is positioned at the beginning of the file.
r+
Open for reading and writing. The stream is positioned at the beginning of the file.
The function ferror tests the error indicator for the stream pointed to by stream, returning non-zero if it is
set. The error indicator can only be reset by the clearerr function.
w
Truncate file to zero length or create text file for writing. The stream is positioned at the beginning
of the file.
The function fileno examines the argument stream and returns its integer descriptor.
w+
Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The
stream is positioned at the beginning of the file.
a
Open for appending (writing at end of file). The file is created if it does not exist. The stream is
positioned at the end of the file.
a+
Open for reading and appending (writing at end of file). The file is created if it does not exist.
The stream is positioned at the end of the file.
The fdopen function associates a stream with the existing file descriptor, fildes. The mode of the stream
(one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with the mode of the file descriptor.
The file position indicator of the new stream is set to that belonging to fildes, and the error and end-of-file
indicators are cleared. Modes "w" or "w+" do not cause truncation of the file. The file descriptor is not
dup’ed, and will be closed when the stream created by fdopen is closed. The result of applying fdopen to a
shared memory object is undefined.
For non-locking counterparts, see unlocked_stdio(3).
ERRORS
These functions should not fail and do not set the external variable errno. (However, in case fileno detects
that its argument is not a valid stream, it must return −1 and set errno to EBADF.)
CONFORMING TO
The functions clearerr, feof, and ferror conform to X3.159-1989 (‘‘ANSI C’’).
SEE ALSO
open(2), stdio(3), unlocked_stdio(3)
RETURN VALUE
Upon successful completion fopen, fdopen and freopen return a FILE pointer. Otherwise, NULL is
returned and the global variable errno is set to indicate the error.
ERRORS
EINVAL
The mode provided to fopen, fdopen, or freopen was invalid.
The fopen, fdopen and freopen functions may also fail and set errno for any of the errors specified for the
routine malloc(3).
The fopen function may also fail and set errno for any of the errors specified for the routine open(2).
The fdopen function may also fail and set errno for any of the errors specified for the routine fcntl(2).
SEE ALSO
open(2), fclose(3), fileno(3)
SOS1-Klausur Manual-Auszug
2006-03-23
1
SOS1-Klausur Manual-Auszug
2006-03-23
1
gethostbyname(3)
gethostbyname(3)
NAME
gets(3S)
gets(3S)
NAME
gethostbyname − get network host entry
gets, fgets − get a string from a stream
fputs, puts − output of strings
SYNOPSIS
#include <netdb.h>
extern int h_errno;
SYNOPSIS
#include <stdio.h>
char *gets(char *s);
struct hostent *gethostbyname(const char *name);
char *fgets(char *s, int n, FILE *stream);
DESCRIPTION
The gethostbyname() function returns a structure of type hostent for the given host name. Here name is
either a host name, or an IPv4 address in standard dot notation, or an IPv6 address in colon (and possibly
dot) notation. (See RFC 1884 for the description of IPv6 addresses.)
The hostent structure is defined in <netdb.h> as follows:
struct hostent {
char
char
int
int
char
}
#define h_addr
*h_name;
**h_aliases;
h_addrtype;
h_length;
**h_addr_list;
/* official name of host */
/* alias list */
/* host address type */
/* length of address */
/* list of addresses */
h_addr_list[0]
/* for backward compatibility */
int fputs(const char *s, FILE *stream);
int puts(const char *s);
DESCRIPTION gets/fgets
The gets( ) function reads characters from the standard input stream (see intro(3)), stdin, into the array
pointed to by s, until a newline character is read or an end-of-file condition is encountered. The newline
character is discarded and the string is terminated with a null character.
The fgets( ) function reads characters from the stream into the array pointed to by s, until n−1 characters
are read, or a newline character is read and transferred to s, or an end-of-file condition is encountered. The
string is then terminated with a null character.
When using gets( ), if the length of an input line exceeds the size of s, indeterminate behavior may result.
For this reason, it is strongly recommended that gets( ) be avoided in favor of fgets( ).
RETURN VALUES
If end-of-file is encountered and no characters have been read, no characters are transferred to s and a null
pointer is returned. If a read error occurs, such as trying to use these functions on a file that has not been
opened for reading, a null pointer is returned and the error indicator for the stream is set. If end-of-file is
encountered, the EOF indicator for the stream is set. Otherwise s is returned.
The members of the hostent structure are:
h_name
The official name of the host.
h_aliases
A zero-terminated array of alternative names for the host.
ERRORS
The gets( ) and fgets( ) functions will fail if data needs to be read and:
h_addrtype
The type of address; always AF_INET at present.
EOVERFLOW
The file is a regular file and an attempt was made to read at or beyond the offset maximum associated with the corresponding stream.
h_length
The length of the address in bytes.
DESCRIPTION puts/fputs
h_addr_list
A zero-terminated array of network addresses for the host in network byte order.
fputs() writes the string s to stream, without its trailing ’\0’.
puts() writes the string s and a trailing newline to stdout.
h_addr The first address in h_addr_list for backward compatibility.
Calls to the functions described here can be mixed with each other and with calls to other output functions
from the stdio library for the same output stream.
RETURN VALUE
The gethostbyname() function returns the hostent structure or a NULL pointer if an error occurs. On error,
the h_errno variable holds an error number.
RETURN VALUE
puts() and fputs() return a non - negative number on success, or EOF on error.
ERRORS
The variable h_errno can have the following values:
HOST_NOT_FOUND
The specified host is unknown.
NO_ADDRESS or NO_DATA
The requested name is valid but does not have an IP address.
SEE ALSO
resolver(3), hosts(5), hostname(7), resolv+(8), named(8)
SPI-Klausur Manual-Auszug
2004-03-16
1
SPI-Klausur Manual-Auszug
2003-02-12
1
ip(7)
ip(7)
NAME
malloc(3)
malloc(3)
NAME
ip − Linux IPv4 protocol implementation
calloc, malloc, free, realloc − Allocate and free dynamic memory
SYNOPSIS
SYNOPSIS
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
void *calloc(size_t nmemb, size_t size);
void *malloc(size_t size);
void free(void *ptr);
void *realloc(void *ptr, size_t size);
tcp_socket = socket(PF_INET, SOCK_STREAM, 0);
raw_socket = socket(PF_INET, SOCK_RAW, protocol);
udp_socket = socket(PF_INET, SOCK_DGRAM, protocol);
DESCRIPTION
DESCRIPTION
The programmer’s interface is BSD sockets compatible. For more information on sockets, see socket(7).
An IP socket is created by calling the socket(2) function as socket(PF_INET, socket_type, protocol).
Valid socket types are SOCK_STREAM to open a tcp(7) socket, SOCK_DGRAM to open a udp(7)
socket, or SOCK_RAW to open a raw(7) socket to access the IP protocol directly. protocol is the IP protocol in the IP header to be received or sent. The only valid values for protocol are 0 and IPPROTO_TCP
for TCP sockets and 0 and IPPROTO_UDP for UDP sockets.
When a process wants to receive new incoming packets or connections, it should bind a socket to a local
interface address using bind(2). Only one IP socket may be bound to any given local (address, port) pair.
When INADDR_ANY is specified in the bind call the socket will be bound to all local interfaces. When
listen(2) or connect(2) are called on a unbound socket the socket is automatically bound to a random free
port with the local address set to INADDR_ANY.
calloc() allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the
allocated memory. The memory is set to zero.
malloc() allocates size bytes and returns a pointer to the allocated memory. The memory is not cleared.
free() frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc() or realloc(). Otherwise, or if free( ptr) has already been called before, undefined behaviour
occurs. If ptr is NULL, no operation is performed.
realloc() changes the size of the memory block pointed to by ptr to size bytes. The contents will be
unchanged to the minimum of the old and new sizes; newly allocated memory will be uninitialized. If ptr
is NULL, the call is equivalent to malloc(size); if size is equal to zero, the call is equivalent to free( ptr).
Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc() or realloc().
RETURN VALUE
ADDRESS FORMAT
An IP socket address is defined as a combination of an IP interface address and a port number. The basic IP
protocol does not supply port numbers, they are implemented by higher level protocols like tcp(7).
struct sockaddr_in {
sa_family_t
sin_family;
u_int16_t
sin_port;
struct in_addr sin_addr;
};
/* Internet address. */
struct in_addr {
u_int32_t
s_addr;
};
For calloc() and malloc(), the value returned is a pointer to the allocated memory, which is suitably aligned
for any kind of variable, or NULL if the request fails.
free() returns no value.
realloc() returns a pointer to the newly allocated memory, which is suitably aligned for any kind of variable
and may be different from ptr, or NULL if the request fails. If size was equal to 0, either NULL or a
pointer suitable to be passed to free() is returned. If realloc() fails the original block is left untouched - it is
not freed or moved.
/* address family: AF_INET */
/* port in network byte order */
/* internet address */
CONFORMING TO
ANSI-C
SEE ALSO
/* address in network byte order */
brk(2), posix_memalign(3)
sin_family is always set to AF_INET. This is required; in Linux 2.2 most networking functions return
EINVAL when this setting is missing. sin_port contains the port in network byte order. The port numbers
below 1024 are called reserved ports. Only processes with effective user id 0 or the
CAP_NET_BIND_SERVICE capability may bind(2) to these sockets.
sin_addr is the IP host address. The addr member of struct in_addr contains the host interface address in
network order. in_addr should be only accessed using the inet_aton(3), inet_addr(3), inet_makeaddr(3)
library functions or directly with the name resolver (see gethostbyname(3)).
Note that the address and the port are always stored in network order. In particular, this means that you
need to call htons(3) on the number that is assigned to a port. All address/port manipulation functions in
the standard library work in network order.
SEE ALSO
sendmsg(2), recvmsg(2), socket(7), netlink(7), tcp(7), udp(7), raw(7), ipfw(7)
SOS1-Klausur Manual-Auszug
2006-03-23
1
SOS1-Klausur Manual-Auszug
2006-03-23
1
memcpy(3)
memcpy(3)
pthread_create/pthread_exit(3)
pthread_create/pthread_exit(3)
NAME
NAME
pthread_create − create a new thread / pthread_exit − terminate the calling thread
memcpy − copy memory area
SYNOPSIS
#include <string.h>
SYNOPSIS
#include <pthread.h>
void *memcpy(void *dest, const void *src, size_t n);
DESCRIPTION
The memcpy() function copies n bytes from memory area src to memory area dest. The memory areas
may not overlap. Use memmove(3) if the memory areas do overlap.
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void *
arg);
void pthread_exit(void *retval);
RETURN VALUE
The memcpy() function returns a pointer to dest.
DESCRIPTION
CONFORMING TO
pthread_create creates a new thread of control that executes concurrently with the calling thread. The new
thread applies the function start_routine passing it arg as first argument. The new thread terminates either
explicitly, by calling pthread_exit(3), or implicitly, by returning from the start_routine function. The latter
case is equivalent to calling pthread_exit(3) with the result returned by start_routine as exit code.
SVID 3, BSD 4.3, ISO 9899
SEE ALSO
bcopy(3), memccpy(3), memmove(3), strcpy(3), strncpy(3)
The attr argument specifies thread attributes to be applied to the new thread. See pthread_attr_init(3) for a
complete list of thread attributes. The attr argument can also be NULL, in which case default attributes are
used: the created thread is joinable (not detached) and has default (non real-time) scheduling policy.
pthread_exit terminates the execution of the calling thread. All cleanup handlers that have been set for the
calling thread with pthread_cleanup_push(3) are executed in reverse order (the most recently pushed handler is executed first). Finalization functions for thread-specific data are then called for all keys that have
non- NULL values associated with them in the calling thread (see pthread_key_create(3)). Finally,
execution of the calling thread is stopped.
The retval argument is the return value of the thread. It can be consulted from another thread using
pthread_join(3).
RETURN VALUE
On success, the identifier of the newly created thread is stored in the location pointed by the thread argument, and a 0 is returned. On error, a non-zero error code is returned.
The pthread_exit function never returns.
ERRORS
EAGAIN
not enough system resources to create a process for the new thread.
EAGAIN
more than PTHREAD_THREADS_MAX threads are already active.
AUTHOR
Xavier Leroy <[email protected]>
SEE ALSO
pthread_join(3), pthread_detach(3), pthread_attr_init(3).
SPI-Klausur Manual-Auszug
2004-03-16
1
SOS1-Klausur Manual-Auszug
2006-03-23
1
socket(3)
socket(3)
socket(3)
socket(3)
activity. An error is then indicated if no response can be elicited on an otherwise idle connection for a
extended period (for instance 5 minutes). A SIGPIPE signal is raised if a process sends on a broken stream;
this causes naive processes, which do not handle the signal, to exit.
NAME
socket − create an endpoint for communication
SYNOPSIS
SOCK_SEQPACKET sockets employ the same system calls as SOCK_STREAM sockets. The only differ-
cc [ flag . . . ] file . . . −lsocket −lnsl [ library . . . ]
ence is that read(2) calls will return only the amount of data requested, and any remaining in the arriving
packet will be discarded.
#include <sys/types.h>
#include <sys/socket.h>
SOCK_DGRAM and SOCK_RAW sockets allow datagrams to be sent to correspondents named in
sendto(3N) calls. Datagrams are generally received with recvfrom(3N), which returns the next datagram
with its return address.
int socket(int domain, int type, int protocol);
DESCRIPTION
socket( ) creates an endpoint for communication and returns a descriptor.
The domain parameter specifies a communications domain within which communication will take place;
this selects the protocol family which should be used. The protocol family generally is the same as the
address family for the addresses supplied in later operations on the socket. These families are defined in
the include file <sys/socket.h>. There must be an entry in the netconfig(4) file for at least each protocol
family and type required. If protocol has been specified, but no exact match for the tuplet family, type, protocol is found, then the first entry containing the specified family and type with zero for protocol will be
used. The currently understood formats are:
PF_UNIX
UNIX system internal protocols
PF_INET
ARPA Internet protocols
An fcntl(2) call can be used to specify a process group to receive a SIGURG signal when the out-of-band
data arrives. It may also enable non-blocking I/O and asynchronous notification of I/O events with SIGIO
signals.
The operation of sockets is controlled by socket level options. These options are defined in the file
<sys/socket.h>. setsockopt(3N) and getsockopt(3N) are used to set and get options, respectively.
RETURN VALUES
A −1 is returned if an error occurs. Otherwise the return value is a descriptor referencing the socket.
ERRORS
The socket( ) call fails if:
The socket has the indicated type, which specifies the communication semantics. Currently defined types
are:
SOCK_STREAM
SOCK_DGRAM
SOCK_RAW
SOCK_SEQPACKET
SOCK_RDM
A SOCK_STREAM type provides sequenced, reliable, two-way connection-based byte streams. An out-ofband data transmission mechanism may be supported. A SOCK_DGRAM socket supports datagrams (connectionless, unreliable messages of a fixed (typically small) maximum length). A SOCK_SEQPACKET
socket may provide a sequenced, reliable, two-way connection-based data transmission path for datagrams
of fixed maximum length; a consumer may be required to read an entire packet with each read system call.
This facility is protocol specific, and presently not implemented for any protocol family. SOCK_RAW
sockets provide access to internal network interfaces. The types SOCK_RAW, which is available only to
the super-user, and SOCK_RDM, for which no implementation currently exists, are not described here.
EACCES
Permission to create a socket of the specified type and/or protocol is denied.
EMFILE
The per-process descriptor table is full.
ENOMEM
Insufficient user memory is available.
ENOSR
There were insufficient STREAMS resources available to complete the operation.
EPROTONOSUPPORT
The protocol type or the specified protocol is not supported within this
domain.
SEE ALSO
close(2), fcntl(2), ioctl(2), read(2), write(2), accept(3N), bind(3N), connect(3N), getsockname(3N), getsockopt(3N), listen(3N), recv(3N), setsockopt(3N), send(3N), shutdown(3N), socketpair(3N),
attributes(5), in(5), socket(5)
protocol specifies a particular protocol to be used with the socket. Normally only a single protocol exists to
support a particular socket type within a given protocol family. However, multiple protocols may exist, in
which case a particular protocol must be specified in this manner. The protocol number to use is particular
to the “communication domain” in which communication is to take place. If a protocol is specified by the
caller, then it will be packaged into a socket level option request and sent to the underlying protocol layers.
Sockets of type SOCK_STREAM are full-duplex byte streams, similar to pipes. A stream socket must be in
a connected state before any data may be sent or received on it. A connection to another socket is created
with a connect(3N) call. Once connected, data may be transferred using read(2) and write(2) calls or
some variant of the send(3N) and recv(3N) calls. When a session has been completed, a close(2) may be
performed. Out-of-band data may also be transmitted as described on the send(3N) manual page and
received as described on the recv(3N) manual page.
The communications protocols used to implement a SOCK_STREAM insure that data is not lost or duplicated. If a piece of data for which the peer protocol has buffer space cannot be successfully transmitted
within a reasonable length of time, then the connection is considered broken and calls will indicate an error
with −1 returns and with ETIMEDOUT as the specific code in the global variable errno. The protocols
optionally keep sockets “warm” by forcing transmissions roughly every minute in the absence of other
SOS1-Klausur Manual-Auszug
2006-03-23
1
SOS1-Klausur Manual-Auszug
2006-03-23
2
stat(2)
stat(2)
stat(2)
stat(2)
The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count,
mode, etc.).
NAME
stat, fstat, lstat − get file status
The following POSIX macros are defined to check the file type:
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int stat(const char * file_name, struct stat *buf );
int fstat(int filedes, struct stat *buf );
int lstat(const char * file_name, struct stat *buf );
DESCRIPTION
These functions return information about the specified file. You do not need any access rights to the file to
get this information but you need search rights to all directories named in the path leading to the file.
is it a regular file?
S_ISDIR(m)
directory?
S_ISCHR(m)
character device?
S_ISBLK(m)
block device?
S_ISFIFO(m)
fifo?
S_ISLNK(m)
symbolic link? (Not in POSIX.1-1996.)
S_ISSOCK(m)
socket? (Not in POSIX.1-1996.)
The following flags are defined for the st_mode field:
stat stats the file pointed to by file_name and fills in buf .
lstat is identical to stat, except in the case of a symbolic link, where the link itself is stat-ed, not the file that
it refers to.
fstat is identical to stat, only the open file pointed to by filedes (as returned by open(2)) is stat-ed in place
of file_name.
They all return a stat structure, which contains the following fields:
struct stat {
dev_t
ino_t
mode_t
nlink_t
uid_t
gid_t
dev_t
off_t
blksize_t
blkcnt_t
time_t
time_t
time_t
};
S_ISREG(m)
st_dev;
/* device */
st_ino; /* inode */
st_mode; /* protection */
st_nlink; /* number of hard links */
st_uid; /* user ID of owner */
st_gid; /* group ID of owner */
st_rdev; /* device type (if inode device) */
st_size; /* total size, in bytes */
st_blksize; /* blocksize for filesystem I/O */
st_blocks; /* number of blocks allocated */
st_atime; /* time of last access */
st_mtime; /* time of last modification */
st_ctime; /* time of last status change */
S_IFMT
S_IFSOCK
S_IFLNK
S_IFREG
S_IFBLK
S_IFDIR
S_IFCHR
S_IFIFO
S_ISUID
S_ISGID
S_ISVTX
S_IRWXU
S_IRUSR
S_IWUSR
S_IXUSR
S_IRWXG
S_IRGRP
S_IWGRP
S_IXGRP
S_IRWXO
S_IROTH
S_IWOTH
S_IXOTH
0170000
0140000
0120000
0100000
0060000
0040000
0020000
0010000
0004000
0002000
0001000
00700
00400
00200
00100
00070
00040
00020
00010
00007
00004
00002
00001
bitmask for the file type bitfields
socket
symbolic link
regular file
block device
directory
character device
fifo
set UID bit
set GID bit (see below)
sticky bit (see below)
mask for file owner permissions
owner has read permission
owner has write permission
owner has execute permission
mask for group permissions
group has read permission
group has write permission
group has execute permission
mask for permissions for others (not in group)
others have read permission
others have write permisson
others have execute permission
The value st_size gives the size of the file (if it is a regular file or a symlink) in bytes. The size of a symlink
is the length of the pathname it contains, without trailing NUL.
The set GID bit (S_ISGID) has several special uses: For a directory it indicates that BSD semantics is to be
used for that directory: files created there inherit their group ID from the directory, not from the effective
group ID of the creating process, and directories created there will also get the S_ISGID bit set. For a file
that does not have the group execution bit (S_IXGRP) set, it indicates mandatory file/record locking.
The value st_blocks gives the size of the file in 512-byte blocks. (This may be smaller than st_size/512 e.g.
when the file has holes.) The value st_blksize gives the "preferred" blocksize for efficient file system I/O.
(Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite.)
The ‘sticky’ bit (S_ISVTX) on a directory means that a file in that directory can be renamed or deleted only
by the owner of the file, by the owner of the directory, and by a privileged process.
Not all of the Linux filesystems implement all of the time fields. Some file system types allow mounting in
such a way that file accesses do not cause an update of the st_atime field. (See ‘noatime’ in mount(8).)
The field st_atime is changed by file accesses, e.g. by execve(2), mknod(2), pipe(2), utime(2) and read(2)
(of more than zero bytes). Other routines, like mmap(2), may or may not update st_atime.
RETURN VALUE
On success, zero is returned. On error, −1 is returned, and errno is set appropriately.
SEE ALSO
chmod(2), chown(2), readlink(2), utime(2), capabilities(7)
The field st_mtime is changed by file modifications, e.g. by mknod(2), truncate(2), utime(2) and write(2)
(of more than zero bytes). Moreover, st_mtime of a directory is changed by the creation or deletion of files
in that directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.
SOS1-Klausur Manual-Auszug
2006-03-23
1
SOS1-Klausur Manual-Auszug
2006-03-23
2
unlink(2)
unlink(2)
NAME
unlink − remove directory entry
SYNOPSIS
#include <unistd.h>
int unlink(const char * path);
DESCRIPTION
The unlink( ) function removes a link to a file. It removes the link named by the pathname pointed to by
path and decrements the link count of the file referenced by the link.
When the file’s link count becomes 0 and no process has the file open, the space occupied by the file will be
freed and the file will no longer be accessible. If one or more processes have the file open when the last
link is removed, the link will be removed before unlink( ) returns, but the removal of the file contents will
be postponed until all references to the file are closed.
RETURN VALUES
Upon successful completion, 0 is returned. Otherwise, −1 is returned and errno is set to indicate the error.
ERRORS
The unlink( ) function will fail and not unlink the file if:
EACCES
Search permission is denied for a component of the path prefix.
EACCES
Write permission is denied on the directory containing the link to be removed.
ENOENT
The named file does not exist or is a null pathname.
ENOTDIR
A component of the path prefix is not a directory.
EPERM
The named file is a directory and the effective user of the calling process is not superuser.
SEE ALSO
rm(1), close(2), link(2), open(2), rmdir(2),
SOS1-Klausur Manual-Auszug
2006-03-23
1
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Related manuals

Download PDF

advertisement