Çб³¿¡¼ ½Ã½ºÅÛ ÇÁ·Î±×·¡¹ÖÀ̶õ´Â°É ¹è¿ì°íÀִµ¥.. @_@;; Á¦°¡ ¸Ó¸®°¡ ³ª»Û°ÇÁö Àß ¸ð¸£°Ú³»¿ä.
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<stdio.h>
#include<unistd.h>
int main(int argc, char * argv[])
{
off_t offset[2];
char * buffer = "that's the way it is";
int file = open(argv[1], O_RDWR | O_APPEND);
offset[0] = lseek(file, 0, SEEK_CUR);
write(file, buffer, strlen(buffer));
offset[1] = lseek(file, 0, SEEK_CUR);
printf("offset before writing: %ld\n", offset[0]); //ÆÄÀÏÀ» ¾²±â Àü¿¡ ¿É¼Â °ª
printf("offset after writing: %ld", offset[1]); //ÆÄÀÏÀ» ¾²°í ³ ÈÄÀÇ ¿É¼Â °ª
return 0;
}
Àú´Â
open(argv[1], O_RDWR | O_APPEND) À¸·Î ¿°í ³ÈÄÀÇ ¿É¼ÂÀÇ °ªÀº ÆÄÀÏÀÇ ³¡À» °¡¸®Å°°í ÀÖ´Â °Í °°¾Æ È®ÀÎ »ï¾Æ ½ÇÇàÀ» Çغ¸¾Ò´õ´Ï
[root@localhost practice]# ./a.out test
offset before writing: 0
offset after writing: 46
ÀÌ·± °á°ú°¡ ³ª¿Ô½À´Ï´Ù.
O_APPENDÀ» ÀÌ¿ëÇؼ openÇÔ¼ö¸¦ ¼öÇàÇصµ lseek(fd, 0, SEEK_CUR)ÀÇ °á°ú°ªÀº ÆÄÀÏÀ» ¾²±âÀü±îÁö´Â 0ÀÎÁö ±Ã±ÝÇÕ´Ï´Ù. |