File: lock.c

package info (click to toggle)
etherdfs-server 0~20180203-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 160 kB
  • sloc: ansic: 1,259; makefile: 15
file content (32 lines) | stat: -rw-r--r-- 575 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * part of ethersrv-linux
 * http://etherdfs.sourceforge.net
 *
 * Copyright (C) 2017 Mateusz Viste
 */

#include <stdio.h>
#include <unistd.h>

#include "lock.h"

/* acquire the lock file */
int lockme(char *lockfile) {
  FILE *fd;
  /* does the file exist? */
  fd = fopen(lockfile, "rb");
  if (fd != NULL) {
    fclose(fd);
    return(-1);
  }
  /* file doesn't seem to exist - create it then */
  fd = fopen(lockfile, "wb");
  if (fd == NULL) return(-1);
  fclose(fd);
  return(0);
}

/* release the lock file */
void unlockme(char *lockfile) {
  unlink(lockfile);
}