-
리눅스 시스템 프로그래밍 기본 명령어 모음C,C++ & Linux 2020. 4. 6. 20:52728x90
파일 입출력
open
#include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> int open(const char* pathname, int oflag); int open(const char* pathname, int oflag, mode_t mode); // 리턴값 : 성공 시 파일 디스크립터, 에러 시 -1 (errno 설정)
close
#include <unistd.h> int close(int fd); // 리턴 값 : 성공 시 0, 에러 시 -1 (errno 설정)
creat
#include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> int creat(const char* pathname, mode_t mode); // 리턴 값 : 성공 시 0, 에러 시 -1 (errno 설정)
lseek
#include <unistd.h> #include <sys/types.h> off_t lseek(int fd, off_t offset, int whence); // 리턴 값 : 성공 시 파일 오프셋, 에러 시 -1 (errno 설정)
read
#include <unistd.h> #include <sys/types.h> // unistd.h 에도 ssize_t 가 선언되어 있긴함 ssize_t read(int fd, void* buf, size_t nbytes); // 리턴 값 : 성공 시 읽어들인 데이터 바이트 수, 파일의 끝에 도달 한 경우 0, 에러 시 -1 (errno 설정)
write
#include <unistd.h> #include <sys/types.h> ssize_t write(int fd, const void* buf, size_t nbytes); // 리턴 값 : 성공 시 기록된 바이트 수, 실패 시 -1 (errno 설정)
pread
#include <unistd.h> #include <sys/types.h> ssize_t pread(int fd, void* buf, size_t nbytes, off_t offset); // 리턴 값 : 성공 시 읽어들인 데이터의 바이트 수, 파일의 끝에 도달한 경우 0, 에러 시 -1 (errno 설정)
pwrite
#include <unistd.h> #include <sys/types.h> ssize_t pwrite(int fd, const void* buf, size_t nbytes, off_t offset); // 리턴 값 : 성공 시 기록된 데이터의 바이트 수, 에러 시 -1 (errno 설정)
dup
#include <unistd.h> int dup(int fd); // 리턴 값 : 성공 시 새로운 파일디스크립터, 에러 시 -1 (errno 설정)
dup2
#include <unistd.h> int dup2(int fd1, int fd2); // 리턴 값 : 성공 시 새로운 파일디스크립터 fd2, 실패 시 -1 (errno 설정)
sync
#include <unistd.h> void sync();
fsnyc
#include <unistd.h> int fsync(int fd); // 리턴 값 : 성공 시 0, 에러 시 -1 (errno 설정)
fdatasync
#include <unistd.h> int fdatasync(int fd); // 리턴 값: 성공 시 0, 에러 시 -1 (errno 설정)
파일속성
stat
#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> int stat(const char* restrict pathname, struct stat* restrict buf); // 리턴 값: 성공 시 0, 에러 시 -1 (errno 설정)
fstat
#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> int fstat(int fd, struct stat* buf); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
lstat
#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> int lstat(const char* pathname, struct stat* buf); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
access
#include <unistd.h> int access(const char* pathname, int mode); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
umask
#include <sys/types.h> #include <sys/stat.h> mode_t umask(mode_t c_mask); // 리턴 값: 이전의 umask 값
chmod
#include <sys/stat.h> int chmod(const char* pathname, mode_t mode); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
fchmod
#include <sys/stat.h> int fchmod(int fd, mode_t mode); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
chown
#include <unistd.h> int chown(const char* pathname, uid_t owner, gid_t group); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
fchown
#include <unistd.h> int fchown(int fd, uid_t owner, gid_t group); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
lchown
#include <unistd.h> int lchown(const char* pathname, uid_t owner, gid_t group); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
truncate
#include <unistd.h> #include <sys/types.h> int trucate(const char* pathname, off_t length); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
ftruncate
#include <unistd.h> #include <sys/types.h> int ftruncate(int fd, off_t length); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
link
#include <unistd.h> int link(const char* existingpath, const char* newpath); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
unlink
#include <unistd.h> int unlink(const char* pathname); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
remove(3)
#include <stdio.h> int remove(const char* pathname); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
rename(2)
#include <stdio.h> int rename(const char* oldname, const char* newname); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
symlink
#include <unistd.h> int symlink(const char* actualpath, const char* sympath); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
readlink
#include <unistd.h> ssize_t readlink(const char* pathname, char* buf, size_t bufsize); // 리턴 값: 성공 시 읽은 바이트 수, 에러 시 -1 (errno 설정)
mkdir
#include <sys/stat.h> #include <sys/types.h> int mkdir(const char* pathname, mode_t mode); // 리턴 값: 성공 시 0, 실패 시 -1 (errno 설정)
rmdir
#include <unistd.h> int rmdir(const char* pathname); // 리턴 값: 성공 시 0, 에러 시 -1 (errno 설정)
opendir(3)
#include <sys/types.h> #include <dirent.h> DIR* opendir(const char* name); // 리턴 값: 성공시 디렉토리 포인터, 에러 시 NULL (errno 설정)
readdir(3)
#include <dirent.h> struct dirent* readdir(DIR* dp); // 리턴 값: 성공 시 dirent 포인터, 디렉토리의 끝 또는 에러 시 NULL (에러시에만 errno 설정)
rewinddir(3)
#include <dirent.h> #include <sys/types.h> void rewinddir(DIR* dp);
closedir(3)
#include <dirent.h> #include <sys/types.h> int closedir(DIR* dp); // 리턴 값: 성공 시 0, 에러 시 -1 리턴 (errno 설정)
telldir(3)
#include <dirent.h> long telldir(DIR* dp); // 리턴 값: 성공 시 디렉토리 내에서의 현재 위치, 에러 시 -1 (errno 설정)
seekdir(3)
#include <dirent.h> void seekdir(DIR* dp, long loc);
chdir
#include <unistd.h> int chdir(const char* pathname); // 리턴 값: 성공 시 0, 에러 시 -1 (errno 설정)
fchdir
#include <unistd.h> int fchdir(int fd); // 리턴 값: 성공 시 0, 에러 시 -1 (errno 설정)
getcwd
#include <unistd.h> char* getcwd(char* buf, size_t size); // 리턴 값: 성공 시 현재 작업 디렉토리 pathname, 에러 시 NULL (errno 설정)
get_current_dir_name
#include <unistd.h> char* get_current_dir_name(); // 리턴 값: 성공 시 현재 작업 디렉토리 pathname, 에러 시 NULL (errno 설정)
시간
utime
#include <utime.h> #include <sys/types.h> int utime(const char* pathname, const struct utimbuf* times); // 성공 시 0, 실패 시 -1 (errno 설정)
time
#include <time.h> time_t time(time_t* tloc); // time_t = long int // 리턴 값: 성공 시 시간을 second로만 표현한 값, 에러 시 -1 (errno 설정)
'C,C++ & Linux' 카테고리의 다른 글
C/C++ read 함수 - 파일을 읽는 함수 (0) 2020.04.22 C/C++ lseek 함수 - 파일 커서(seek pointer) 조정 (0) 2020.04.22 C/C++ creat 함수 - 파일 생성 (0) 2020.04.21 C/C++ open 함수 - 파일 생성 / 읽기 / 쓰기 (0) 2020.04.21 string.h 함수 모음 (0) 2020.04.06