]> git.8kb.co.uk Git - pgpool-ii/pgpool-ii_2.2.5/blob - pool_path.h
Attempt to send a proper failure message to frontend when authentication
[pgpool-ii/pgpool-ii_2.2.5] / pool_path.h
1 /* -*-pgsql-c-*- */
2 /*
3  *
4  * $Header: /cvsroot/pgpool/pgpool-II/pool_path.h,v 1.2 2008/01/29 01:56:36 y-asaba Exp $
5  *
6  * pgpool: a language independent connection pool server for PostgreSQL 
7  * written by Tatsuo Ishii
8  *
9  * Portions Copyright (c) 2003-2008,    PgPool Global Development Group
10  * Portions Copyright (c) 2004, PostgreSQL Global Development Group
11  *
12  * Permission to use, copy, modify, and distribute this software and
13  * its documentation for any purpose and without fee is hereby
14  * granted, provided that the above copyright notice appear in all
15  * copies and that both that copyright notice and this permission
16  * notice appear in supporting documentation, and that the name of the
17  * author not be used in advertising or publicity pertaining to
18  * distribution of the software without specific, written prior
19  * permission. The author makes no representations about the
20  * suitability of this software for any purpose.  It is provided "as
21  * is" without express or implied warranty.
22  *
23  * pool_path.h.: interface to pool_path.c
24  *
25  */
26
27 #ifndef POOL_PATH_H
28 #define POOL_PATH_H
29
30 /*
31  * MAXPGPATH: standard size of a pathname buffer in PostgreSQL (hence,
32  * maximum usable pathname length is one less).
33  *
34  * We'd use a standard system header symbol for this, if there weren't
35  * so many to choose from: MAXPATHLEN, MAX_PATH, PATH_MAX are all
36  * defined by different "standards", and often have different values
37  * on the same platform!  So we just punt and use a reasonably
38  * generous setting here.
39  */
40 #define MAXPGPATH       1024
41
42 #define IS_DIR_SEP(ch)  ((ch) == '/')
43 #define is_absolute_path(filename) \
44 ( \
45     ((filename)[0] == '/') \
46 )
47
48 /*
49  * StrNCpy
50  *  Like standard library function strncpy(), except that result string
51  *  is guaranteed to be null-terminated --- that is, at most N-1 bytes
52  *  of the source string will be kept.
53  *  Also, the macro returns no result (too hard to do that without
54  *  evaluating the arguments multiple times, which seems worse).
55  *
56  *  BTW: when you need to copy a non-null-terminated string (like a text
57  *  datum) and add a null, do not do it with StrNCpy(..., len+1).  That
58  *  might seem to work, but it fetches one byte more than there is in the
59  *  text object.  One fine day you'll have a SIGSEGV because there isn't
60  *  another byte before the end of memory.  Don't laugh, we've had real
61  *  live bug reports from real live users over exactly this mistake.
62  *  Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead.
63  */
64 #define StrNCpy(dst,src,len) \
65     do \
66     { \
67         char * _dst = (dst); \
68         size_t _len = (len); \
69 \
70         if (_len > 0) \
71         { \
72             strncpy(_dst, (src), _len); \
73             _dst[_len-1] = '\0'; \
74         } \
75     } while (0)
76
77 extern void get_parent_directory(char *path);
78 extern void join_path_components(char *ret_path, const char *head, const char *tail);
79 extern void canonicalize_path(char *path);
80         
81 #endif /* POOL_PATH_H */