tags 331139 + patch
thanks

The attached patch fixes up the code to work nicely with a modern
glibc and GCC.

The patch:

1) Replaces the use of __linux__ with __GNU_LIBRARY__, for use with a
   modern glibc dev_t.  NOTE!  With the 64-bit dev_t in 2.6 kernels,
   glibc implements a 64-bit dev_t, but obviously the kernel macros
   are no longer useful: it would break userspace compatibility with
   older kernels (or newer, depending upon the kernel headers in use).
2) Removes a Linux special-case for CUA devices.  This was dependent
   upon the kernel headers, and was useless (/dev/cua* have been
   deprecated since forever), so was removed.
3) ANSI-fies the source and headers.  K&R C is no longer acceptable on
   a current GNU/Linux system.

None of these changes alter the ABI or API, though it does now require
an ISO/ANSI C compiler (not a real loss).

Regards,
Roger


diff -urN lockdev-1.0.1.original/src/lockdev.c lockdev-1.0.1/src/lockdev.c
--- lockdev-1.0.1.original/src/lockdev.c        2005-10-01 21:08:00.000000000 
+0100
+++ lockdev-1.0.1/src/lockdev.c 2005-10-01 21:42:50.927918819 +0100
@@ -123,9 +123,10 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/file.h>
-#if defined (__linux__)
-#include <linux/kdev_t.h>
-#include <linux/major.h>
+#if defined (__GNU_LIBRARY__)
+#include <sys/sysmacros.h>
+# define MAJOR(dev) gnu_dev_major (dev)
+# define MINOR(dev) gnu_dev_minor (dev)
 #elif defined (__FreeBSD_kernel__) || defined(__NetBSD_kernel__) || 
defined(__OpenBSD_kernel__)
 #  define MAJOR(dev) ((dev & 0xff00) >> 8)
 #  define MINOR(dev) (dev & 0xffff00ff)
@@ -167,14 +168,14 @@
 
 /* exported by the interface file lockdev.h */
 void
-liblockdev_incr_debug()
+liblockdev_incr_debug (void)
 {
        liblockdev_debug++;
 }
 
 /* exported by the interface file lockdev.h */
 void
-liblockdev_reset_debug()
+liblockdev_reset_debug (void)
 {
        liblockdev_debug = 0;
 }
@@ -191,13 +192,12 @@
  * All types uses the macro LOCK_PATH
  */
 
-#if defined (__linux__) || defined (__FreeBSD_kernel__) || 
defined(__NetBSD_kernel__) || defined(__OpenBSD_kernel__)
+#if defined (__GNU_LIBRARY__) || defined (__FreeBSD_kernel__) || 
defined(__NetBSD_kernel__) || defined(__OpenBSD_kernel__)
 
 /* for internal use */
 static inline int
-_dl_filename_0( name, pid)
-       char * name;
-       const pid_t pid;
+_dl_filename_0 (char        *name,
+               const pid_t  pid)
 {
        int l;
        _debug( 3, "_dl_filename_0 (pid=%d)\n", (int)pid);
@@ -209,19 +209,12 @@
 
 /* for internal use */
 static inline int
-_dl_filename_1( name, st)
-       char * name;
-       const struct stat * st;
+_dl_filename_1 (char              *name,
+               const struct stat *st)
 {
        int l;
        int add = 0;
        _debug( 3, "_dl_filename_1 (stat=%d)\n", (int)st->st_rdev);
-#if defined (__linux__)
-       /* this changes the major from 5 to 4 if it was a cua device */
-       if ( (int)st->st_rdev >= (TTYAUX_MAJOR*256)+64
-                       && (int)st->st_rdev <= (TTYAUX_MAJOR*256)+127 )
-               add = (TTY_MAJOR - TTYAUX_MAJOR)*256;
-#endif /* __linux__ */
        /* lockfile of type /var/lock/LCK.004.064 */
        l = sprintf( name, "%s/LCK.%03d.%03d", LOCK_PATH,
                (int)MAJOR( add+st->st_rdev), (int)MINOR( add+st->st_rdev));
@@ -231,9 +224,8 @@
 
 /* for internal use */
 static inline int
-_dl_filename_2( name, dev)
-       char * name;
-       const char * dev;
+_dl_filename_2 (char       *name,
+               const char *dev)
 {
        int l;
        _debug( 3, "_dl_filename_2 (dev=%s)\n", dev);
@@ -249,8 +241,7 @@
 
 /* handler for signals */
 static void
-_dl_sig_handler( sig)
-       int sig;
+_dl_sig_handler (int sig)
 {
        signal( sig, _dl_sig_handler);
        switch( sig ) {
@@ -276,8 +267,7 @@
 
 /* for internal use */
 static int
-_dl_get_semaphore( flag)
-       int flag;
+_dl_get_semaphore (int flag)
 {
        int flag2 = flag;
 
@@ -328,8 +318,7 @@
 
 /* for internal use */
 static int
-_dl_unlock_semaphore( value)
-       int value;
+_dl_unlock_semaphore (int value)
 {
        if ( semaphore != -1 ) {
                _debug( 1, "_dl_unlock_semaphore(return=%d)=%d\n", value, 
semaphore);
@@ -346,14 +335,14 @@
 
 /* for internal use */
 static inline int
-_dl_lock_semaphore()
+_dl_lock_semaphore (void)
 {
        return  _dl_get_semaphore( 0);
 }
 
 /* for internal use */
 static inline int
-_dl_block_semaphore()
+_dl_block_semaphore (void)
 {
        return  _dl_get_semaphore( 3);
 }
@@ -363,8 +352,7 @@
 /* for internal use */
 /* zero means: we don't own the lock; maybe someone else */
 static pid_t
-_dl_check_lock( lockname)
-       const char * lockname;
+_dl_check_lock(const char *lockname)
 {
        /* no check on lockname */
        FILE *fd = 0;
@@ -465,8 +453,7 @@
 
 /* for internal use */
 static char *
-_dl_check_devname( devname)
-       const char * devname;
+_dl_check_devname (const char *devname)
 {
        int l;
        const char * p;
@@ -494,8 +481,7 @@
 /* exported by the interface file lockdev.h */
 /* ZERO means that the device wasn't locked, but could have been locked later 
*/
 pid_t
-dev_testlock( devname)
-       const char * devname;
+dev_testlock(const char *devname)
 {
        const char * p;
        char device[MAXPATHLEN+1];
@@ -565,8 +551,7 @@
 
 /* exported by the interface file lockdev.h */
 pid_t
-dev_lock( devname)
-       const char * devname;
+dev_lock (const char *devname)
 {
        const char * p;
        char device[MAXPATHLEN+1];
@@ -722,9 +707,8 @@
 
 /* exported by the interface file lockdev.h */
 pid_t
-dev_relock( devname, old_pid)
-       const char * devname;
-       const pid_t old_pid;
+dev_relock (const char  *devname,
+           const pid_t  old_pid)
 {
        const char * p;
        char device[MAXPATHLEN+1];
@@ -808,9 +792,8 @@
 
 /* exported by the interface file lockdev.h */
 pid_t
-dev_unlock( devname, pid)
-       const char * devname;
-       const pid_t pid;
+dev_unlock (const char *devname,
+           const pid_t pid)
 {
        const char * p;
        char device[MAXPATHLEN+1];
diff -urN lockdev-1.0.1.original/src/lockdev.h lockdev-1.0.1/src/lockdev.h
--- lockdev-1.0.1.original/src/lockdev.h        1999-12-01 11:39:42.000000000 
+0000
+++ lockdev-1.0.1/src/lockdev.h 2005-10-01 21:45:10.864485710 +0100
@@ -42,32 +42,22 @@
 extern "C" {
 #endif
 
-#ifndef        __P
-#  if defined  (__STDC__) || defined (_AIX) \
-               || (defined (__mips) && defined (_SYSTYPE_SVR4)) \
-               || defined(WIN32) || defined(__cplusplus)
-#    define    __P(protos) protos
-#  else
-#    define    __P(protos) ()
-#  endif
-#endif
-
 #include <sys/types.h>
 
-
 /* API of the library */
 
-void   liblockdev_incr_debug __P(());
-void   liblockdev_reset_debug __P(());
-
-pid_t  dev_testlock __P(( const char * devname));
+void liblockdev_incr_debug (void);
+void liblockdev_reset_debug (void);
 
-pid_t  dev_lock __P(( const char * devname));
+pid_t dev_testlock (const char *devname);
 
-pid_t  dev_relock __P(( const char * devname, const pid_t old_pid));
+pid_t dev_lock (const char *devname);
 
-pid_t  dev_unlock __P(( const char * devname, const pid_t pid));
+pid_t dev_relock (const char * devname,
+                 const pid_t  old_pid);
 
+pid_t dev_unlock (const char * devname,
+                 const pid_t pid);
 
 #ifdef __cplusplus
 };
diff -urN lockdev-1.0.1.original/src/sample.c lockdev-1.0.1/src/sample.c
--- lockdev-1.0.1.original/src/sample.c 1999-12-01 11:50:09.000000000 +0000
+++ lockdev-1.0.1/src/sample.c  2005-10-01 21:47:45.236270097 +0100
@@ -2,7 +2,8 @@
 #include "lockdev.h"
 
 void
-usage() {
+usage (void)
+{
        fprintf( stderr, "Usage: sample [-lurd] <device>\n" );
        exit( -1 );
 }
@@ -11,7 +12,8 @@
 
 
 int
-main( int argc, char *argv[] )
+main (int   argc,
+      char *argv[])
 {
        int i, chld;
        char *p, *dev, ch;
diff -urN lockdev-1.0.1.original/src/ttylock.h lockdev-1.0.1/src/ttylock.h
--- lockdev-1.0.1.original/src/ttylock.h        1999-12-01 11:51:35.000000000 
+0000
+++ lockdev-1.0.1/src/ttylock.h 2005-10-01 21:46:36.764760454 +0100
@@ -32,52 +32,37 @@
 extern "C" {
 #endif
 
-#ifndef        __P
-#  if defined  (__STDC__) || defined (_AIX) \
-               || (defined (__mips) && defined (_SYSTYPE_SVR4)) \
-               || defined(WIN32) || defined(__cplusplus)
-#    define    __P(protos) protos
-#  else
-#    define    __P(protos) ()
-#  endif
-#endif
-
 #include <lockdev.h>
 
-
 /* API of the library */
 
-int    ttylock __P(( char * devname));
-int    ttywait __P(( char * devname));
-int    ttyunlock __P(( char * devname));
-int    ttylocked __P(( char * devname));
+int ttylock (char * devname);
+int ttywait (char * devname);
+int ttyunlock (char * devname);
+int ttylocked (char * devname);
 
 
 static inline int
-ttylock( devname)
-       char * devname;
+ttylock(char *devname)
 {
        /* should set errno ? */
-       return( dev_lock( devname) == 0 ? 0 : -1);
+       return dev_lock( devname) == 0 ? 0 : -1;
 }
 
 static inline int
-ttyunlock( devname)
-       char * devname;
+ttyunlock (char *devname)
 {
-       return( dev_unlock( devname, 0));
+       return dev_unlock(devname, 0);
 }
 
 static inline int
-ttylocked( devname)
-       char * devname;
+ttylocked(char *devname)
 {
-       return( dev_testlock( devname) == 0 ? 0 : -1);
+       return dev_testlock( devname) == 0 ? 0 : -1;
 }
 
 static inline int
-ttywait( devname)
-       char * devname;
+ttywait (char *devname)
 {
        while( dev_testlock( devname)) {
                sleep(1);


-- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                Debian GNU/Linux        http://www.debian.org/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to