http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_programming&no=795 [º¹»ç]
¾²·¹µå¸¦ ÀÌ¿ëÇÏ¿©..º¹»ç ÇÁ·Î±×·¥À» ¸¸µå´Âµ¥¿ä..¾Æ·¡¿¡¼..
PERMS °¡..¼³Á¤µÇ¾îÀÖ¾î º¹»ç ÇÁ·Î±×·¥À» ¸¸µé¸é..rw------- ÀÇ ÀÏÁ¤ÇÑ Æ۹̼Ǹ¸ ÀÌ·ç¾îÁö°ÔµÇ´Âµ¥¿ä..
ÀÌ°É Á¶±Ý ÀÀ¿ëÇؼ Æ۹̼ÇÀ» ¿øº»ÆÄÀÏ¿¡¼ º¹»çÇÏ´Â ÇÁ·Î±×·¥À¸·Î º¯°æÇÏ´Â °ÍÀÔ´Ï´Ù..
ÀÌ°É..¾Æ¸¶µµ Á¦»ý°¢¿£..umask() ÇÔ¼ö..¸¦ ÀÌ¿ëÇÏ´Â °Å¶ó°í »ý°¢ÇßÁö¿ä..
ÇÏÁö¸¸ ¿øº» ÈÀÏÀÇ Æ۹̼ÇÀ» ºÒ·¯¿À´Â°Ô ½±Áö°¡ ¾Ê³×¿ä...
ºÎŹµå¸®°Ú½À´Ï´Ù..^^;; 1ÁÖÀϵ¿¾È ÀÌÃ¥ ÀúÃ¥ ã¾Æº¸¸é¼ .Âü..Àú¸¦ ¹Ì¿öÇÏ°Ô µÇ´õ±º¿ä..¤Ì_¤Ì
½Ã½ºÅÛ ÇÁ·Î±×·¡¹Ö ÂÊÀÌ°ÚÁö¿ä..ÀÌ°Ô ¸®´ª½º Áß½ÉÀ¸·Î § ÇÁ·Î±×·¥À̶ó´Â Á¡µµ ÀÌÇØÇØÁֽñ¸¿ä..±×·³ ¸íÄèÇÑ ´ä±Û ±â´Ù¸®°Ú½À´Ï´Ù...
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#define PERMS (S_IRUSR | S_IWUSR) //À̺κÐÀÌ ¹®Á¦ÀÇ ÆÛ¹Ì¼Ç ºÎºÐ...
#define READ_FLAGS O_RDONLY
#define WRITE_FLAGS (O_WRONLY | O_CREAT | O_TRUNC)
static int readwrite(int fromfd, int tofd)
{
char buf[1024];
int bytesread;
if((bytesread = read(fromfd, buf, 1024)) < 0) return -1;
if(bytesread == 0) return 0;
if(write(tofd, buf, bytesread) < 0) return -1;
return bytesread;
}
static int copyfile(int fromfd, int tofd)
{
int bytesread; int totalbytes = 0;
while((bytesread = readwrite(fromfd, tofd)) > 0)
totalbytes += bytesread;
return totalbytes;
}
static void *copyfilemalloc(void *arg)
{
int *bytesp; int infd, outfd;
infd = *((int *)(arg));
outfd = *((int *)(arg) +1);
if((bytesp = (int *)malloc(sizeof(int))) == NULL)
return NULL;
*bytesp = copyfile(infd, outfd);
close(infd); close(outfd);
return bytesp;
}
int main(int argc, char *argv[])
{
int *bytesptr; int error; int fds[2]; pthread_t tid;
//1ÁÖÀϵ¿¾È ÀÌ »çÀÌ¿¡´Ù°¡ umaskÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¿© Âü ¸¹Àº ÀϵéÀ» Çغ¸¾ÒÁö¸¸..¿øº»ÆÄÀÏÀÇ ÆÛ¹Ì¼Ç ºÒ·¯¿À±â¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù..
if(argc != 3){
fprintf(stderr, "Usage : %s fromfile tofile\n",argv[0]);
return 1;
}
if(((fds[0] = open(argv[1], READ_FLAGS)) == -1) ||
((fds[1] = open(argv[2], WRITE_FLAGS, PERMS)) == -1)){ // Á¦»ý°¢¿¡ ¼öÁ¤µÇ¾î¾ß ÇÒ ºÎºÐ...PERMS°¡ ¾Æ¹«·¡µµ ¹®Á¦Àεí..½Í³×¿ä...
perror("Failed to open the files"); return 2;
}
if(error = pthread_create(&tid, NULL, copyfilemalloc, fds)){
fprintf(stderr, "Failed to create thread: %s\n", strerror(error));
return 3;
}
if(error = pthread_join(tid, (void **)&bytesptr)){
fprintf(stderr, "Failed to join thread: %s\n", strerror(error));
return 4;
}
printf("Number of bytes copied: %d\n", *bytesptr);
return 0;
}
¼÷Á¦´Â È¥ÀÚ¼...È¥ÀÚ¼...ÇÏÁö¸¸ ½Ã°£ÀÌ..¾ó¸¶ ¾øÀ¸´Ï±î ÀÌ·¸°Ô¶óµµ..
±×¸®°í..¾ï¿ïÇØ¿ä..-_-;; ÀÌ·¸°Ô Àú·¸°Ô Çغôµ¥...¾ÈµÇ´Ï±î..
¼÷Á¦ ¸øÇÏ´õ¶óµµ ¾Ë¾Æ¾ß°Ú½À´Ï´Ù...±×·³..¿À´Ã ÇÏ·ç ÇູÇϼ¼¿ä.. |
Hit : 2839 Date : 2005/04/26 07:28
|