creat - open
d=open('_,O_WRONLY|O_TRUNC|O_CREAT,mode);
creat -
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int creat(const char *path, mode_t perms)
path - '
perms -
-1
. , :
ssize_t read(int fdes, char *buf, size_t count);
:
ssize_t write(int fdes, char *buf, size_t count);
. . - . , , .
int close(int fdes);
.
lseek . ³ - .
#include <sys/types.h>
#include <unistd.h>
off_t lseek(int fd, off_t offset, int whence);
fd -
pos -
whence - pos
-1 ( errno)
whence :
SEEK_SET pos ( ).
SEEK_CUR pos . , . pos 0 .
SEEK_ENO pos . , . pos 0 .
- , . , write 0. read, , 0. , write , , , .
- .
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
int main() {
int fdIn; //
|
|
int fdOut; //
char buf[256]; //
char InName[20], OutName[20]; //
ssize_t nRd;
//
printf("' -> ");
gets(InName);
printf("' -> ");
gets(OutName);
// ³
if((fdIn=open(InName, O_RDONLY))==-1)
{perror(" "); exit(-1);}
if((fdOut=open(OutName, O_WRONLY|O_CREAT,644))==-1)
{ perror(" "); close(fdIn);
exit(-2); }
//
while((nRd=read(fdIn, buf, 256))>0)
{ if(write(fdOut, buf, nRd)<nRd)
{ perror(" "); close(fdIn); close(fdOut); exit(-3); }
}
close(fdIn); close(fdOut);
printf(" \n"); exit(0);
}
" " (O_RDONLY). . -1. perror(). . , (errno) .
, . " " (O_WRONLY) (O_CREAT). , (644), ( ).
5.
³ . . , .
- . ' .
- . ' .
- . ' .
- . . , - . .
- , . ' .
- , , . .
- . .
- . ' .
- . .
- , . .
- , , ' . , .
- , . ' .
- , , . .
- , , . .
- , , . .
|
|