openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/nss-pam-ldapd/0.9.8-r0/nss-pam-ldapd-0.9.8/nslcd/nslcd.c
static int is_locked(const char* filename)
{
    int fd;
    if (filename != NULL)
    {
        errno = 0;
        if ((fd = open(filename, O_RDWR, 0644)) < 0)
        {
            if (errno == ENOENT)
                return 0; /* if file doesn't exist it cannot be locked */
            log_log(LOG_ERR, "cannot open lock file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        if (lockf(fd, F_TEST, 0) < 0)
        {
            if (close(fd))
                log_log(LOG_WARNING, "problem closing fd: %s", strerror(errno));
            return -1;
        }
        if (close(fd))
            log_log(LOG_WARNING, "problem closing fd: %s", strerror(errno));
    }
    return 0;
}
/* test to see if we can lock the specified file */
test to see if we can lock the specified file
test to see if we can lock the specified file
static int is_locked(const char* filename)
{
    int fd;
    if (filename != NULL)
    {
        errno = 0;
        if ((fd = open(filename, O_RDWR, 0644)) < 0)
        {
            if (errno == ENOENT)
                return 0; 
            log_log(LOG_ERR, "cannot open lock file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        if (lockf(fd, F_TEST, 0) < 0)
        {
            if (close(fd))
                log_log(LOG_WARNING, "problem closing fd: %s", strerror(errno));
            return -1;
        }
        if (close(fd))
            log_log(LOG_WARNING, "problem closing fd: %s", strerror(errno));
    }
    return 0;
}
static int is_locked ( const char * filename ) { int fd ; if ( filename != NULL ) { errno = 0 ; if ( ( fd = open ( filename , O_RDWR , 0644 ) ) < 0 ) { if ( errno == ENOENT ) return 0 ; log_log ( LOG_ERR , " " , filename , strerror ( errno ) ) ; exit ( EXIT_FAILURE ) ; } if ( lockf ( fd , F_TEST , 0 ) < 0 ) { if ( close ( fd ) ) log_log ( LOG_WARNING , " " , strerror ( errno ) ) ; return -1 ; } if ( close ( fd ) ) log_log ( LOG_WARNING , " " , strerror ( errno ) ) ; } return 0 ; }
test to see if we can lock the specified file
test to see if we can lock the specified file
/* if file doesn't exist it cannot be locked */