No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / file_id.c
blob63af4b6f431fde56cd222f2c3eda7ea70c08feeb
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* file_id 3
6 /* SUMMARY
7 /* file ID printable representation
8 /* SYNOPSIS
9 /* #include <file_id.h>
11 /* const char *get_file_id(fd)
12 /* int fd;
14 /* int check_file_id(fd, id)
15 /* int fd;
16 /* const char *id;
17 /* DESCRIPTION
18 /* get_file_id() queries the operating system for the unique identifier
19 /* for the specified file and returns a printable representation.
20 /* The result is volatile. Make a copy if it is to be used for any
21 /* appreciable amount of time.
23 /* check_file_id() tests if an open file matches the given
24 /* printable FILE ID representation.
26 /* Arguments:
27 /* .IP fd
28 /* A valid file descriptor that is associated with an open file.
29 /* .IP id
30 /* Printable file ID.
31 /* DIAGNOSTICS
32 /* All errors are fatal.
33 /* LICENSE
34 /* .ad
35 /* .fi
36 /* The Secure Mailer license must be distributed with this software.
37 /* AUTHOR(S)
38 /* Wietse Venema
39 /* IBM T.J. Watson Research
40 /* P.O. Box 704
41 /* Yorktown Heights, NY 10598, USA
42 /*--*/
44 /* System library. */
46 #include <sys_defs.h>
47 #include <sys/stat.h>
48 #include <string.h>
50 /* Utility library */
52 #include <msg.h>
53 #include <vstring.h>
55 /* Global library. */
57 #include "file_id.h"
59 /* get_file_id - lookup file ID, convert to printable form */
61 const char *get_file_id(int fd)
63 static VSTRING *result;
64 struct stat st;
66 if (result == 0)
67 result = vstring_alloc(1);
68 if (fstat(fd, &st) < 0)
69 msg_fatal("fstat: %m");
70 vstring_sprintf(result, "%lX", (long) st.st_ino);
71 return (vstring_str(result));
74 /* check_file_id - make sure file name matches ID */
76 int check_file_id(int fd, const char *name)
78 return (strcmp(get_file_id(fd), name));