|
김가영 님이 쓰신 글 :
: 어떠한 프로그램인지 설명및 주석좀 부탁드려요...
:
: #include <stdio.h>
: #include <dirent.h>
: #include <string.h>
: #include <stdlib.h>
:
: int match(const char*, const char*);
:
: void find_entry(char* dirname, char* preffix, int cont)
: {
: static DIR *dp=NULL;
: struct dirent *d;
:
: if(dp==NULL || cont==0)
: {
: if(dp != NULL)
: close(dp);
:
: if((dp=opendir(dirname))==NULL)
: exit(0);
: }
:
: while(d=readdir(dp))
: {
: if(d->d_ino==0)
: continue;
: if(match(d->d_name, preffix))
: printf("%s \n", d->d_name);
: }
: closedir(dp);
: dp=NULL;
: }
:
: int match(const char* s1, const char* s2)
: {
: if(strlen(s1) > strlen(s2))
: return (strncmp(s1, s2, strlen(s2))==0);
: else return 0;
: }
:
: main(int argc, char** argv)
: {
: if(argc != 3) printf("Useage : directory preffix \n");
: find_entry(argv[1], argv[2], 0);
:
: }
:
:
: ===============================================================================================
:
: #include <stdio.h>
: #include <fcntl.h>
:
: void main(int argc, char** argv)
: {
: int fd1, fd2;
: char buf[1];
: ssize_t r;
:
: close(1);
:
: if( (fd2=open(argv[2], O_WRONLY | O_CREAT)) == -1)
: {
: perror("fd2 open error");
: }
:
: if( (fd1=open(argv[1], O_RDONLY))==-1)
: {
: perror("fd1 open error");
: }
:
: while( (r=read(fd1, &buf, sizeof(buf) ))>0)
: {
: printf("%s", buf);
: }
: }
|