new libbb func: xmalloc_realpath (+ use it where makes sense)
[oweals/busybox.git] / include / libbb.h
index a2b9a82b2fc3c3714e7ba8ae1be8f5ae54073e9b..e92e4db1c0b73a9e315cf37a6e1daa582e4c447f 100644 (file)
 #include <unistd.h>
 #include <utime.h>
 
-#ifdef CONFIG_SELINUX
+#if ENABLE_SELINUX
 #include <selinux/selinux.h>
 #endif
 
-#ifdef CONFIG_LOCALE_SUPPORT
+#if ENABLE_LOCALE_SUPPORT
 #include <locale.h>
 #else
-#define setlocale(x,y)
+#define setlocale(x,y) ((void)0)
 #endif
 
 #include "pwd_.h"
 #include "grp_.h"
+/* ifdef it out, because it may include <shadow.h> */
+/* and we may not even _have_ <shadow.h>! */
 #if ENABLE_FEATURE_SHADOWPASSWDS
 #include "shadow_.h"
 #endif
@@ -59,7 +61,7 @@
 #include <limits.h>
 #include <sys/param.h>
 #ifndef PATH_MAX
-#define  PATH_MAX         256
+#define PATH_MAX 256
 #endif
 
 /* Tested to work correctly (IIRC :]) */
 #endif
 
 /* buffer allocation schemes */
-#ifdef CONFIG_FEATURE_BUFFERS_GO_ON_STACK
+#if ENABLE_FEATURE_BUFFERS_GO_ON_STACK
 #define RESERVE_CONFIG_BUFFER(buffer,len)           char buffer[len]
 #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char buffer[len]
 #define RELEASE_CONFIG_BUFFER(buffer)      ((void)0)
 #else
-#ifdef CONFIG_FEATURE_BUFFERS_GO_IN_BSS
+#if ENABLE_FEATURE_BUFFERS_GO_IN_BSS
 #define RESERVE_CONFIG_BUFFER(buffer,len)  static          char buffer[len]
 #define RESERVE_CONFIG_UBUFFER(buffer,len) static unsigned char buffer[len]
 #define RELEASE_CONFIG_BUFFER(buffer)      ((void)0)
@@ -189,6 +191,18 @@ struct sysinfo {
 extern int sysinfo(struct sysinfo* info);
 
 
+/* Size-saving "small" ints (arch-dependent) */
+#if defined(i386) || defined (__mips__)
+/* add other arches which benefit from this... */
+typedef signed char smallint;
+typedef unsigned char smalluint;
+#else
+/* for arches where byte accesses generate larger code: */
+typedef int smallint;
+typedef unsigned smalluint;
+#endif
+
+
 extern void chomp(char *s);
 extern void trim(char *s);
 extern char *skip_whitespace(const char *);
@@ -224,6 +238,7 @@ extern DIR *warn_opendir(const char *path);
 
 char *xgetcwd(char *cwd);
 char *xreadlink(const char *path);
+char *xmalloc_realpath(const char *path);
 extern void xstat(char *filename, struct stat *buf);
 extern pid_t spawn(char **argv);
 extern pid_t xspawn(char **argv);
@@ -338,17 +353,20 @@ uint16_t xatou16(const char *numstr);
 /* These parse entries in /etc/passwd and /etc/group.  This is desirable
  * for BusyBox since we want to avoid using the glibc NSS stuff, which
  * increases target size and is often not needed on embedded systems.  */
-extern long bb_xgetpwnam(const char *name);
-extern long bb_xgetgrnam(const char *name);
-/*extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);*/
-extern char *bb_getpwuid(char *name, long uid, int bufsize);
-extern char *bb_getgrgid(char *group, long gid, int bufsize);
-/* from chpst */
+extern long xuname2uid(const char *name);
+extern long xgroup2gid(const char *name);
+/* wrapper: allows string to contain numeric uid or gid */
+extern unsigned long get_ug_id(const char *s, long (*xname2id)(const char *));
+/* from chpst. Does not die, returns 0 on failure */
 struct bb_uidgid_t {
         uid_t uid;
         gid_t gid;
 };
-extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/);
+extern int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok);
+/* what is this? */
+/*extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);*/
+extern char *bb_getpwuid(char *name, long uid, int bufsize);
+extern char *bb_getgrgid(char *group, long gid, int bufsize);
 
 
 enum { BB_GETOPT_ERROR = 0x80000000 };
@@ -380,6 +398,7 @@ extern const char *msg_eol;
 extern int logmode;
 extern int die_sleep;
 extern int xfunc_error_retval;
+extern void sleep_and_die(void) ATTRIBUTE_NORETURN;
 extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
 extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
 extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
@@ -465,7 +484,7 @@ extern void bb_do_delay(int seconds);
 extern void change_identity(const struct passwd *pw);
 extern const char *change_identity_e2str(const struct passwd *pw);
 extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args);
-#ifdef CONFIG_SELINUX
+#if ENABLE_SELINUX
 extern void renew_current_security_context(void);
 extern void set_current_security_context(security_context_t sid);
 #endif
@@ -484,7 +503,6 @@ extern void vfork_daemon_rexec(int nochdir, int noclose,
                int argc, char **argv, char *foreground_opt);
 #endif
 extern int get_terminal_width_height(int fd, int *width, int *height);
-extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *));
 
 int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
 void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
@@ -636,7 +654,7 @@ extern const char bb_default_login_shell[];
 #define DEFAULT_SHELL_SHORT_NAME     (bb_default_login_shell+6)
 
 
-#ifdef CONFIG_FEATURE_DEVFS
+#if ENABLE_FEATURE_DEVFS
 # define CURRENT_VC "/dev/vc/0"
 # define VC_1 "/dev/vc/1"
 # define VC_2 "/dev/vc/2"