Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / JAWS / clients / WebSTONE / src / nsapi-includes / base / util.h
blob2ff89e81128cbadc5f054b6bd8fc92f2b427100f
1 /*
2 * Copyright (c) 1994, 1995. Netscape Communications Corporation. All
3 * rights reserved.
5 * Use of this software is governed by the terms of the license agreement for
6 * the Netscape Communications or Netscape Comemrce Server between the
7 * parties.
8 */
11 /* ------------------------------------------------------------------------ */
15 * util.h: A hodge podge of utility functions and standard functions which
16 * are unavailable on certain systems
18 * Rob McCool
22 #ifndef HTTPD_UTIL_H
23 #define HTTPD_UTIL_H
25 #include "buffer.h" /* filebuf for getline */
27 #include <time.h> /* struct tm */
30 /* ------------------------------ Prototypes ------------------------------ */
34 * getline scans in buf until it finds a LF or CRLF, storing the string in
35 * l. It will terminate the string and return:
37 * 0 when done, with the scanned line (minus CR or LF) in l
38 * 1 upon EOF, with the scanned line (minus CR or LF) in l
39 * -1 on error with the error description in l (uses lineno for information)
42 int util_getline(filebuf *buf, int lineno, int maxlen, char *l);
46 * can_exec returns 1 if you can execute the file described by finfo, and
47 * 0 if you can't.
50 #ifdef XP_UNIX
51 #include <sys/stat.h>
52 #include <sys/types.h>
54 int util_can_exec(struct stat *finfo, uid_t uid, gid_t gid);
56 #endif /* XP_UNIX */
58 * env_create creates a new environment with the given env, with n new
59 * entries, and places the current position that you should add your
60 * entries with at pos.
62 * If env is NULL, it will allocate a new one. If not, it will reallocate
63 * that one.
66 char **util_env_create(char **env, int n, int *pos);
69 * util_env_str allocates a string from the given name and value and
70 * returns it. It does not check for things like = signs in name.
73 char *util_env_str(char *name, char *value);
76 * env_replace replaces the occurrence of the given variable with the
77 * value you give.
80 void util_env_replace(char **env, char *name, char *value);
83 * util_env_free frees an environment.
86 void util_env_free(char **env);
89 * util_env_find looks through env for the named string. Returns the
90 * corresponding value if the named string is found, or NULL if not.
92 char *util_env_find(char **env, char *name);
96 * hostname gets the local hostname. Returns NULL if it can't find a FQDN.
97 * You are free to realloc or free this string.
100 char *util_hostname();
104 * chdir2path changes the current directory to the one that the file
105 * path is in. path should point to a file. Caveat: path must be a writable
106 * string. It won't get modified permanently.
109 int util_chdir2path(char *path);
112 * is_mozilla checks if the given user-agent is mozilla, of at least
113 * the given major and minor revisions. These are strings to avoid
114 * ambiguities like 1.56 > 1.5
117 int util_is_mozilla(char *ua, char *major, char *minor);
120 * is_url will return 1 if the given string seems to be a URL, or will
121 * return 0 otherwise.
123 * Because of stupid news URLs, this will return 1 if the string has
124 * all alphabetic characters up to the first colon and will not check for
125 * the double slash.
128 int util_is_url(char *url);
131 * util_later_than checks the date in the string ims, and if that date is
132 * later than or equal to the one in the tm struct lms, then it returns 1.
134 * Handles RFC 822, 850, and ctime formats.
137 int util_later_than(struct tm *lms, char *ims);
141 * util_uri_is_evil returns 1 if a URL has ../ or // in it.
143 int util_uri_is_evil(char *t);
146 * util_uri_parse gets rid of /../, /./, and //.
148 * Assumes that either the string starts with a /, or the string will
149 * not .. right off of its beginning. As such, ../foo.gif will
150 * not be changed, although /../foo.gif will become /foo.gif.
153 void util_uri_parse(char *uri);
156 * util_uri_unescape unescapes the given URI in place (% conversions only).
159 void util_uri_unescape(char *s);
162 * util_uri_escape escapes any nasty chars in s and copies the string into d.
163 * If d is NULL, it will allocate and return a properly sized string.
164 * Warning: does not check bounds on a given d.
166 * util_url_escape does the same thing but does it for a url, i.e. ?:+ is
167 * not escaped.
170 char *util_uri_escape(char *d, char *s);
171 char *util_url_escape(char *d, char *s);
174 * util_sh_escape places a \ in front of any shell-special characters.
175 * Returns a newly-allocated copy of the string.
178 char *util_sh_escape(char *s);
181 * util_itoa converts the given integer to a string into a.
184 int util_itoa(int i, char *a);
187 * util_vsprintf and util_sprintf are simplified clones of the System V
188 * vsprintf and sprintf routines.
190 * Returns the number of characters printed. Only handles %d and %s,
191 * does not handle any width or precision.
194 #include <stdarg.h>
196 int util_vsprintf(char *s, register char *fmt, va_list args);
197 int util_sprintf(char *s, char *fmt, ...);
199 /* These routines perform bounds checks. */
200 int util_vsnprintf(char *s, int n, register char *fmt, va_list args);
201 int util_snprintf(char *s, int n, char *fmt, ...);
203 #endif