chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / serial.c
index c8e2295190d42fa74955c9873bf50d413e298b08..c2c53b8d07eaa8b9a2e092c4ec45faf4c15a4ae7 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/15 03:32:07  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/14 16:21:17  james
  * *** empty log message ***
  *
@@ -55,10 +58,11 @@ static char rcsid[] = "$Id$";
 
 #define NLOCKFILES     10
 
-typedef struct {
-char *lockfiles[NLOCKFILES];
-char *potential_lockfiles[NLOCKFILES];
-struct timeval last_content_check;
+typedef struct
+{
+  char *lockfiles[NLOCKFILES];
+  char *potential_lockfiles[NLOCKFILES];
+  struct timeval last_content_check;
 } Serial_lock;
 
 typedef struct
@@ -71,118 +75,136 @@ typedef struct
 
 
 static int
-chown_uucp(fd)
-int fd;
+chown_uucp (fd)
+     int fd;
 {
-    static int uuid = -1, ugid;
-    struct passwd *pw;
-
-    if (uuid <0) {
-        if (pw = getpwnam("uucp")) {
-            uuid = pw->pw_uid;
-            ugid = pw->pw_gid;
-        } else {
-               return -1;
-       }
+  static int uuid = -1, ugid;
+  struct passwd *pw;
+
+  if (uuid < 0)
+    {
+      if (pw = getpwnam ("uucp"))
+        {
+          uuid = pw->pw_uid;
+          ugid = pw->pw_gid;
+        }
+      else
+        {
+          return -1;
+        }
     }
-    return fchown(fd, uuid, ugid);
+  return fchown (fd, uuid, ugid);
 }
 
-int make_lockfile(char *name)
+int
+make_lockfile (char *name)
 {
-char buf[1024],tmpfn[1024];
-char *ptr;
-int fd;
-int i;
+  char buf[1024], tmpfn[1024];
+  char *ptr;
+  int fd;
+  int i;
 
-strcpy(tmpfn,name);
+  strcpy (tmpfn, name);
 
-ptr=rindex(tmpfn,'/');
-if (!ptr) return -1;
+  ptr = rindex (tmpfn, '/');
+  if (!ptr)
+    return -1;
 
-ptr++;
+  ptr++;
 
-ptr+=sprintf(ptr,"LTMP.%d",getpid());
-*ptr=0;
+  ptr += sprintf (ptr, "LTMP.%d", getpid ());
+  *ptr = 0;
 
-i=sprintf(buf,"%10d\n",getpid());
+  i = sprintf (buf, "%10d\n", getpid ());
 
-fd=open(tmpfn,O_WRONLY|O_CREAT|O_TRUNC,0444);
-if (fd<0) {
-       unlink(tmpfn);
-       return -1;
-}
+  fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444);
+  if (fd < 0)
+    {
+      unlink (tmpfn);
+      return -1;
+    }
 
-write(fd,buf,i);
-fchmod(fd,044);
-if( chown_uucp(fd)) {
-       close(fd);
-       unlink(tmpfn);
-       return -1;
-}
+  write (fd, buf, i);
+  fchmod (fd, 044);
+  if (chown_uucp (fd))
+    {
+      close (fd);
+      unlink (tmpfn);
+      return -1;
+    }
 
-close(fd);
+  close (fd);
 
-if (link(tmpfn,name)<0) {
-       unlink(tmpfn);
-       return -1;
-}
+  if (link (tmpfn, name) < 0)
+    {
+      unlink (tmpfn);
+      return -1;
+    }
 
-unlink(tmpfn);
-return 0;
+  unlink (tmpfn);
+  return 0;
 }
 
 
 
-void construct_lock_file_name_by_name(char *ptr)
+void
+construct_lock_file_name_by_name (char *ptr)
 {
 
-printf("lock by file %s\n",ptr);
+  printf ("lock by file %s\n", ptr);
 
 }
-void construct_lock_file_name_by_device(dev_t dev)
+
+void
+construct_lock_file_name_by_device (dev_t dev)
 {
 
-printf("lock by dev %x\n",dev);
+  printf ("lock by dev %x\n", dev);
 }
 
 
 #define DEV "/dev/"
-int construct_possible_lock_files(char *device)
+int
+construct_possible_lock_files (char *device)
 {
-int nl;
-struct dirent *de;
-DIR *d;
-struct stat dev_stat,ent_stat;
-char buf[1024];
+  int nl;
+  struct dirent *de;
+  DIR *d;
+  struct stat dev_stat, ent_stat;
+  char buf[1024];
 
 
-if (stat(device,&dev_stat)) return -1;
-if (!S_ISCHR(dev_stat.st_mode)) return -1;
+  if (stat (device, &dev_stat))
+    return -1;
+  if (!S_ISCHR (dev_stat.st_mode))
+    return -1;
 
-construct_lock_file_name_by_device(dev_stat.st_rdev);
+  construct_lock_file_name_by_device (dev_stat.st_rdev);
 
-construct_lock_file_name_by_name(device);
+  construct_lock_file_name_by_name (device);
 
-for (d=opendir(DEV);(de=readdir(d));)
-{
-strcpy(buf,DEV);
-strcat(buf,de->d_name);
+  for (d = opendir (DEV); (de = readdir (d));)
+    {
+      strcpy (buf, DEV);
+      strcat (buf, de->d_name);
 
-if (stat(buf,&ent_stat)) continue;
-if (!S_ISCHR(ent_stat.st_mode)) continue;
-if (ent_stat.st_rdev!=dev_stat.st_rdev) continue;
+      if (stat (buf, &ent_stat))
+        continue;
+      if (!S_ISCHR (ent_stat.st_mode))
+        continue;
+      if (ent_stat.st_rdev != dev_stat.st_rdev)
+        continue;
 
-construct_lock_file_name_by_name(buf);
+      construct_lock_file_name_by_name (buf);
 
-}
-closedir(d);
+    }
+  closedir (d);
 
 }
 
 
-static void 
-serial_check_lock(Serial *t)
+static void
+serial_check_lock (Serial * t)
 {
 }
 
@@ -207,8 +229,9 @@ serial_read (TTY * _t, void *buf, int len)
   Serial *t = (Serial *) _t;
   int red, done = 0;
 
-  serial_check_lock(t);
-  if (t->blocked) return 0;
+  serial_check_lock (t);
+  if (t->blocked)
+    return 0;
 
   do
     {
@@ -236,8 +259,9 @@ ptty_write (TTY * _t, void *buf, int len)
   int writ, done = 0;
   Serial *t = (Serial *) _t;
 
-  serial_check_lock(t);
-  if (t->blocked) return 0;
+  serial_check_lock (t);
+  if (t->blocked)
+    return 0;
 
   do
     {
@@ -271,7 +295,7 @@ serial_open (char *path)
 
   default_termios (&termios);
 
-  fd=open(path,O_RDWR);
+  fd = open (path, O_RDWR);
 
   set_nonblocking (fd);