⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locking.c

📁 GSM猫管理程序
💻 C
字号:
/*SMS Server Tools 3Copyright (C) Keijo Kasvihttp://smstools3.kekekasvi.com/Based on SMS Server Tools 2 from Stefan Fringshttp://www.meinemullemaus.de/This program is free software unless you got it under another license directlyfrom the author. You can redistribute it and/or modify it under the terms ofthe GNU General Public License as published by the Free Software Foundation.Either version 2 of the License, or (at your option) any later version.*/#include "locking.h"#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <string.h>#include <fcntl.h>#include <limits.h>#include <unistd.h>int lockfile( char*  filename){  char lockfilename[PATH_MAX +5];  int lockfile;  struct stat statbuf;  char pid[20];  if (!filename)    return 0;  if (strlen(filename) >= sizeof(lockfilename))    return 0;  strcpy(lockfilename,filename);  strcat(lockfilename,".LOCK");  if (stat(lockfilename,&statbuf))  {    lockfile=open(lockfilename,O_CREAT|O_EXCL|O_WRONLY,0644);    if (lockfile>=0)    {      sprintf(pid,"%i\n",(int)getpid());      write(lockfile,&pid,strlen(pid));      close(lockfile);      return 1;    }  }  return 0;}int islocked( char*  filename){  char lockfilename[PATH_MAX +5];  struct stat statbuf;  if (!filename)    return 0;  if (strlen(filename) >= sizeof(lockfilename))    return 0;  strcpy(lockfilename,filename);  strcat(lockfilename,".LOCK");  if (stat(lockfilename,&statbuf))    return 0;  return 1;}int unlockfile( char*  filename){  char lockfilename[PATH_MAX +5];  if (!filename)    return 0;  if (strlen(filename) >= sizeof(lockfilename))    return 0;  strcpy(lockfilename,filename);  strcat(lockfilename,".LOCK");  if (unlink(lockfilename))    return 0;  return 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -