Library Functions. The UNIX system provides a large number of C functions as libraries. Some of these implement frequently used operations, while others are very specialized in their application.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
The standard C library functions are declared in a set of header files that are commonly placed in the /usr/include directory on UNIX systems.
$man 3 intro
printf(“a"); write(STDOUT_FILENO, “b", 1); printf(“c\n");
write is a system call -- it is implemented by the interface between user mode (where programs like yours run) and the operating system kernel (which handlesthe actual writing to disk when bytes are written to a file).
printf is a C standard library function -- it is implemented by library code loaded into your user mode program.
The C standard library output functions buffer their output, by default until end-of-line is reached. When the buffer is full or terminated with a newline, it is written to the file via a call to write from the library implementation.
Therefore, the output via printf is not sent to the operating system write immediately. In your example, you buffer the letter 'u', then immediately write the letter 'm', then append "d\n" to the buffer and the standard library makes the call write(STDOUT_FILENO, "ud\n");
unsigned char hold;
unsigned char *buffer, *curp;
here in the above statement we are declaring a file pointer.there are many modes of opening a file. they are read ,write,append ..
0: The standard input
1: The standard output
2: The standard error output
int open(const char *path, intoflags);
int open(const char *path, int oflags, mode_t mode);
O_RDONLY Open for read-only
O_WRONLY Open for write-only
O_RDWR Open for reading and writing
the same time. If the file already exists, open will fail.
Int creat(const char *path, mode_t mode);
size_t read( intfd, void *buf, size_tnbytes );
size_t write(intfildes, const void *buf, size_tnbytes);
nread = read(0, buffer, 128);
if (nread == -1)
write(2, “A read error has occurred\n”, 26);
if ((write(1,buffer,nread)) != nread)
write(2, “A write error has occurred\n”,27);
printf("Read source file : ");
printf("Read destination file : ");
if(fd1==-1 || fd2==-1)
printf("Files cannt be opened");
intfstat(intfildes, struct stat *buf);
int stat(const char *path, struct stat *buf);
intlstat(const char *path, struct stat *buf);
dev_tst_dev; /* file system ID * /
ino_tst_ino; /*File inode number*/
mode_tst_mode; /* contains file type and access flags*/
nlink_tst_nlink: /* Hard Link count*/
uid_tst_uid /* File user Id*/
gid_tst_gid /* File group ID*/
dev_tst_rdev; /* Contains major and minor device numbers*/
off_tst_size /* File size in nuber of bytes*/
time_tst_atime; /* Last access time*/
time_tst_mtime; /* Last modification time time*/
time_tst_ctime; /* Last status change time time*/
The following POSIX macros are defined to check the file type using the st_mode field:
-- that is from beginning to the end of the file.
long lseek(intfile_descriptor, long offset, int whence)
whence new position
0 (SEEK_SET) offset bytes into the file
1(SEEK_CUR) current position in the file
2 (SEEK_END) current end-of-file position plus offset