File: lock.C

package info (click to toggle)
peruser 4b33-10
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,944 kB
  • ctags: 1,064
  • sloc: cpp: 22,397; perl: 2,733; makefile: 345; sh: 335
file content (25 lines) | stat: -rw-r--r-- 500 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
#include <stdio.h>
#include <stdlib.h>

#include "npfile.h"

int NP_File::lock( int l )
{
   snprintf( buffer, sizeof buffer, "%s:lock", filename );

   if ( l )
   {
      FILE *file;
      if (( file = fopen( buffer, "r" )) != NULL )
      {
         fclose( file );
         snprintf( error_message, sizeof error_message, "NP_File: lock(): "
                   "file %s is locked by another process.", filename );
         return 1;
      }
   }
   else
      remove( buffer );
   
   return 0;
}