CHAR2INT('s','u','p','e')
};
+static const char* kLockFilename = "snark.lock";
+static int gLockFd = -1;
+
int FindKeywordCode(int word)
{
for(int i = 0; i < NUMBER_OF_COMMANDS; i++) { // find keyword code
return Phase[code];
}
+void atExitCleanup(void) {
+#ifndef __CYGWIN__
+ if (gLockFd >= 0) {
+ close(gLockFd);
+ if (unlink(kLockFilename) != 0) {
+ fprintf(stderr, "Error unlinking lock file\n");
+ }
+ }
+#endif
+}
int snark(int argc, char *argv[])
{
// bug 179 - swr - 10/30/05
#ifndef __CYGWIN__
// bug 167 - swr - 9/24/05
- int lfp=open("snark.lock",O_RDWR|O_CREAT,0640);
- if (lfp<0) {
+ gLockFd = open(kLockFilename,O_RDWR|O_CREAT,0640);
+ if (gLockFd < 0) {
fprintf(stderr, "can't create lock file in current directory - check directory permissions\n");
exit(1); /* can not open */
}
- if (lockf(lfp,F_TLOCK,0)<0) {
+ if (lockf(gLockFd,F_TLOCK,0)<0) {
fprintf(stderr, "multiple snark executions in the same directory are not allowed!\n");
exit(0); /* can not lock */
}
/* only first instance continues */
char str[10];
sprintf(str,"%d\n",getpid());
- write(lfp,str,strlen(str)); /* record pid to lockfile */
+ write(gLockFd,str,strlen(str)); /* record pid to lockfile */
+
+ atexit(atExitCleanup);
+
#endif
// bug 187 - allow input filename on command line - swr - 11/11/05
};
fprintf(output, "\n");
+
return 0;
}