chapter03 파일과 디렉토리 (06)
디렉토리 생성 함수
#include <sys/types.h>
#include <sys/stat.h>
int mkdir(const char *path디렉토리가 포함된 경로 , mode_t mode접근권한) 수행 성공시 0을 리턴, 실패시 -1을 리턴
디렉토리 삭제 함수
#include <unistd.h>
int rmdir(const char *path 삭제할 경로) 삭제하려는 디렉토리는 .과 ..을 제외하고 비어있어야함.수행 성공시 0을 리턴, 실패시 -1을 리턴
디렉토리 이름 변경 함수
#include <stdio.h>
int rename(const char *old 기존 이름, const char *new바꿀 이름);두번째 인자로 지정한 이름이 존재시 해당 디렉토리 지움




현재 작업 디렉토리 위치
#include <unistd.h>
char *getcwd(char *buf 주소, size_t size버퍼의 크기); 수행중 오류 발생시 null리턴. 버퍼주소가 null이면 직접 malloc으로 메모리 할당후 주소 리턴
디렉토리 이동
#include <unistd.h>
int chdir(const char *path); 성공시 0리턴, 실패시 -1리턴. 절대경로 상대경로 모두 사용 가능

디렉토리 열기 함수
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *dirname 열려는 디렉토리 명);
###close와 dirclose 차이###
둘다 파일 디스크립터와 디렉토리 핸들을 닫는 명령어이다.
하지만 둘은 사용되는 대상의 차이 때문에 서로 다른 명령어이다.
'close' 명령어는 파일 디스크립터를 닫는다.
'closedir' 명령어는 디렉토리 핸들을 닫는다.
디렉토리 닫기 함수
#include <sys/types.h>
#include <dirent.h>
int closedir(DIR *dirp닫으려는 디렉토리를 가르키는 포인터);
디렉토리 정보 읽기 함수
#include <sys/types.h>
#include <dirent.h>
struct dirent *readdir(DIR *dirp정보를 읽어올 디렉토리를 가르키는 포인터);

디렉토리 오프셋
-파일을 열고 읽고 쓸때 파일 오프셋이 이동하는 것 처럼 디렉토리도 마찬가지로 디렉토리 오프셋이 이동한다.
long telldir(DIR *dirp);현재 오프셋의 위치를 알려줌
void seekdir(DIR *dirp, long loc);loc으로 지정한 위치로 오프셋을 이동시킨다.
void rewinddir(DIR *dirp);제일 처음으로 오프셋 이동
