/** @file fcntl_lock.c @date 2009/9/30 @author 유영창 frog@falinux.com FALinux.Co.,Ltd. @brief fcntl_lock 함수 Ver 0.1.0 @modify @todo @bug @remark @warning */ //---------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int flock_create( char *key_file ) { int fd; fd = open( key_file, O_CREAT|O_RDWR ); if( fd < 0 ) return -1; return fd; } int flock_free( int key_fd ) { if( key_fd >= 0 ) close( key_fd ); } int flock_lock( int key_fd ) { struct flock lock; if( key_fd < 0 ) return key_fd; lock.l_type = F_WRLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; return fcntl(key_fd, F_SETLKW, &lock); } int flock_unlock( int key_fd ) { struct flock lock; if( key_fd < 0 ) return key_fd; lock.l_type = F_UNLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; fcntl(key_fd, F_SETLK, &lock); }