69
B10, B134, B150, B200, B300, B600,
B1200, B1800, B2400, B4800,
B9600, B19200,
and
B38400
.
The
cfgetispeed()
function does not do anything to the hardware. It merely returns the
value stored by a previous call to
tcgetattr()
.
Reference:
P 7.1.2.7.1
Conversions:
This function is new to POSIX. BSD and System V required the application to store
device-dependent information and use the
ioctl()
function to pass that information to the
system. That code should be replaced by this function. See
tcsetattr()
for more
info
rmation.
This function is not supported in BSD or SVR1-3.
Notes:
Baud rates are defined by symbols, such as
B110,B1200,B2400
. The actual number
returned for any given speed may change from system to system.
See Chapter 8,
Terminal I/O,
for more information.
P
age 232
cfgetospeed()
—Reads terminal output baud rate.
Synopsis:
#include <termios.h>
speed_t cfgetospeed(const struct termios *p);
Arguments:
p
Pointer to a struct termios.
Returns:
Code for the baud rate.
Description:
The
cfgetospeed()
function returns a code for the terminal speed stored in a
struct
termios
. The codes are defined in
<termios.h>
by the macros
BO, B50, B75,
B10, B134, B150, 200, 300, B600
,
B1200, B1800, B2400, B4800,
B9600, B19200
, and
B38400
.
The
cfgetospeed()
function does not do anything to the hardware. It merely returns the
value stored by a previous call to
tcgetattr()
.
Reference:
68
P 7.1.2.7.1
Conversions:
This function is new to POSIX. BSD and System V required the application to store
device-dependent information and use the
ioctl()
function to pass that information to the
system. That code should be replaced by this function. See
tcsetattr()
for more
info
rmation.
This function is not supported in BSD or SVR1-3.
Notes:
Baud rates are defined by symbols, such as
B110
,
B1200
,
B2400
. The actual number
returned for any given speed may change from system to system.
See Chapter 8,
Terminal I/O,
for more information.
P
age 233
cfsetispeed()
—Sets terminal input baud rate.
Synopsis:
#include <termios.h>
int cfsetispeed(struct termios *p, speed_t speed);
Arguments:
p
Pointer to a
struct
termios
.
speed
Code for the desired speed.
Returns:
Zero on success and
-1
on error.
Description:
The
cfsetispeed()
function stores a code for the terminal speed stored in a
struct
termios
. The codes are defined in
<termios.h>
by the macros
B0, B50, B75,
B10, B134, B150, B200, B300, B600,
B1200, B1800, B2400, B4800,
B9600, B19200
, and
B38400
.
The
cfsetispeed()
function does not do anything to the hardware. It merely stores a value
for use by
tcsetattr()
.
Reference:
P 7.1.2.7.1
Conversions:
64
This function is new to POSIX. BSD and System V required the application to store
device-dependent information and use the
ioctl()
function to pass that information to the
system. That code should be replaced by this function. See
tcsetattr()
for more
info
rmation.
This function is not supported in BSD or SVR1-3.
Notes:
This function merely stores a value in the
termios
structure. It does not change the terminal
speed until a
tcsetattr()
is done. It does not detect impossible terminal speeds.
See Chapter 8,
Terminal I/0,
for more information.
P
age 234
cfsetospeed()
—Sets terminal output baud rate.
Synopsis:
#include <termios.h>
int cfsetospeed(struct termios *p, speed_t speed);
Arguments:
p
Pointer to a
struct
termios
.
speed
Code for the desired speed.
Returns:
Zero on success and
-1
on error.
Description:
The
cfsetospeed()
function stores a code for the terminal speed stored in a
struct
termios
. The codes are defined in
<termios.h>
by the macros
B0, B50, B75,
B10, B134, B150, B200, B300, B600, B1200, B1800, B2400, B4800,
B9600, B19200,
and
B38400
.
The
cfsetospeed()
function does not do anything to the hardware. It merely stores a value
for use by
tcsetattr()
.
Reference:
P 7.1.2.7.1
Conversions:
This function is new to POSIX. BSD and System V required the application to store
51
device-dependent information and use the
ioctl()
function to pass that information to the
system. That code should be replaced by this function. See
tcsetattr()
for more
info
rmation.
This function is not supported in BSD or SVR1-3.
Notes:
This function merely stores a value in the termios structure. It does not change the terminal
speed until a
tcsetattr()
is done. It does not detect impossible terminal speeds.
See Chapter 8,
Terminal I/O,
for more information.
P
age 235
chdir()
—Changes the current working directory.
Synopsis:
#include <unistd.h>
int chdir(const char *path);
Arguments:
path
Pointer to the name of the new directory.
Returns:
Zero on success and
-1
on failure.
Errors:
EACCES, ENAMETOOLONG, ENOENT, ENOTDIR
Description:
The
chdir()
function causes the directory named by
path
to become the current working
directory; that is, the starting point for searches of pathnames not beginning with a slash.
If
chdir()
detects an error, the current working directory is not changed.
Reference:
P 5.2.1.1
Conversions:
Add to the list of headers:
#include <unistd.h>
Notes:
P
age 236
C# Word - Word Conversion in C#.NET using other external third-party dependencies like Adobe Acrobat. Word SDK to convert Word document to PDF document. demo code for Word to TIFF image conversion
adding image to pdf form; adding an image to a pdf in acrobat
57
chmod()
—Changes file mode.
Synopsis:
#include <sys/types.h>
#include <sys/stat.h>
int chmod(const char *path, mode_t mode);
Arguments:
path
Pointer to pathname of the file to modify.
mode
New permission bits,
S_ISUID
and
S_ISGID
.
Returns:
Zero on success and -1 on failure.
Errors:
EACCES, ENAMETOOLONG, ENOENT, ENOTDIR, EPERM, EROFS
Description:
Set the file permission bits, the set user ID bit, and the set group ID bit for the file named by
path
to
mode
. If the effective user ID does not match the owner of the file and the calling
process does not have the appropriate privileges,
chmod()
returns
-1
and sets
errno
to
EPERM
.
Reference:
P 5.6.4.1
Conversions:
SVR1-2 and BSD did not specify symbols for the mode bits; they gave absolute values. Change
these to symbols using the following key:
Value
Symbol
Meaning
04000
S_ISUID
Set user ID on execution.
02000
S_ISGID
Set group ID on execution.
00400
S_IRUSR
Allow the owner to read the file.
00200
S_IWUSR
Allow the owner to write the file.
00100
S_IXUSR
Allow the owner to execute the file.
58
P
age 237
Value
Symbol
Meaning
00040
S_IRGRP
Allow a process with a group ID that matches the file's group to read
the file.
00020
S_IWGRP
Allow a process with a group ID that matches the file's group to write
the file.
00010
S_IXGRP
Allow a process with a group ID
that matches the file's group to
execute the file.
00004
S_IROTH
Allow anyone to read the file.
00002
S_IWOTH
Allow anyone to write the file.
00001
S_IXOTH
Allow anyone to execute the file.
BSD and SVR1-3 used
int
for
mode
instead of
mode_t
Notes:
S_ISUID
and
S_ISGID
may be ignored on some implementations.
Do not attempt to set any bits not listed above.
P
age 238
chown()
—Changes the owner and/or group of a file.
Synopsis:
#include <sys/types.h>
#include <unistd.h>
int chown(const char *path, uid_t owner, gid_t group);
Arguments:
path
Pointer to path name of the file to modify.
owner
New owner ID.
group
New group ID.
Returns:
Zero on success and
-1
on failure.
56
Errors:
EACCES, EINVAL, ENAMETOOLONG, ENOENT, ENOTDIR, EPERM, EROFS
Description:
The user ID and group ID of the file named by
path
are set to
owner
and
path
,
respectively.
For regular files, the set group
ID(S_ISGID)
and set user
ID(S_ISUID)
bits are cleared.
Some systems consider it a security violation to allow the owner of a file to be changed. If
users are billed for disk space usage, loaning a file to another user could result in incorrect
billing. The
chown()
function may be restricted to privileged users
for some or all files. The
group ID can still be changed to one of the supplementary group IDs.
Reference:
P 5.6.5.1
Conversions:
Add to the list of headers:
#include <unistd.h>
SVR1-3 and BSD used
int
for
owner
and
group
.
P
age 239
Notes:
This function may be restricted for some files. The
pathconf()
function can be used to test
the
_PC_CHOWN_RESTRICTED
flag.
P
age 240
clearerr()
—Clears end-of-file and error indicators for a stream.
Synopsis:
#include <stdio.h>
void clearerr(FILE *stream);
Arguments:
stream
File to use.
Returns:
No value is returned.
52
Description:
The error and end-of-file indicators for
stream
are cleared.
Reference:
C 4.9.10.1
Notes:
P
age 241
clock()
—Determines processor time used.
Synopsis:
#include <time.h>
clock_t clock(void);
Arguments:
None.
Returns:
The processor time used or
-1
if unknown.
Description:
The
clock()
function returns an approximation of the amount of CPU time used by the
program. The value returned has a type of
clock_t
. To convert a
clock_t
to seconds,
divide by the macro
CLOCKS_PER_SECOND
.
Reference:
C 4.12.2.1
Conversions:
This function is not supported in BSD.
SVR1-2 return
long
.
SVR3 used the header
<sys/types.h>
.
Notes:
The standards say nothing about when the timer for the
clock()
function is reset. It may not
be reset while your process is running. To measure how much time your program used, call
clock()
at the start of your program and again at the end. The difference
between the two
values is the answer.
This function is required by Standard C and is not part of the POSIX standard.
49
P
age 242
close()
—Closes a file.
Synopsis:
#include <unistd.h>
int close(int fildes);
Arguments:
fildes
The file descriptor to close.
Returns:
Zero on success and
-1
on failure.
Errors:
EBADF, EINTR
Description:
The
close()
function deallocates the file descriptor named by
fildes
and makes it
available for reuse. All outstanding record locks owned by this process for the file are
unlocked.
If it is the last file descriptor that refers to a given file, the following additional steps are taken:
1.
Any remaining pipe or FIFO data is discarded.
2.
If the link count of the file is zero, the space occupied by the file is freed and the file is no
longer accessible.
Reference:
P 6.3.1.1
Conversions:
Add to the list of headers:
#include <unistd.h>
Notes:
A signal can interrupt the
close()
function. In that case,
close()
returns
-1
with
errno
set to
EINTR
. The file may or may not be closed.
P
age 243
62
closedir()
—Ends directory read operation.
Synopsis
:
#include <sys/types.h>
#include <dirent.h>
int closedir(DIR *dirp);
Arguments
:
dirp
Pointer returned by
opendir()
.
Returns:
Zero on success and
-1
on failure.
Errors:
EBADF
Description:
The directory stream associated with
dirp
is closed. The value in
dirp
may not be usable
after a call to
closedir()
.
Reference:
P 5.1.2.1
Conversions:
BSD used the header
<sys/dir.h>
, which must be replaced by
<dirent.h>
. The BSD
struct
direct
must be replaced by the POSIX equivalent struct dirent. BSD also provided
the
seekdir()
and
telldir()
functions that are not supported by POSIX.
SVR1-2 did not provide this function. SVR1-2 programs read directories as ordinary files.
Directory entries are 14-byte names and 2-byte I-node numbers. These programs must be
changed to use
readdir()
.
Notes:
The argument to
closedir()
must be a pointer returned by
opendir()
. If it is not, the
results are not portable and most likely unpleasant.
P
age 244
cos()
—Computes the cosine function.
Synopsis:
#include <math.h>
Documents you may be interested
Documents you may be interested