Merge branch 'master' of ssh://git.samba.org/data/git/samba into talloc-next
[ira/wip.git] / lib / util / util.h
index bfd09ba20be21fe5d67f22e20977af7375093ecf..1f6e3b193b3d0a9f9970428e19c45611e7401fca 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef _SAMBA_UTIL_H_
 #define _SAMBA_UTIL_H_
 
+#include <netinet/in.h>
+
 #if _SAMBA_BUILD_ == 4
 #include "../lib/util/charset/charset.h"
 #endif
@@ -52,7 +54,7 @@ extern const char *panic_action;
 #ifdef DEVELOPER
 #define SMB_ASSERT(b) do { if (!(b)) { \
         DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \
-                __FILE__, __LINE__, #b)), smb_panic("assert failed: " #b); }} while(0)
+                __FILE__, __LINE__, #b)); smb_panic("assert failed: " #b); }} while(0)
 #else
 /* redefine the assert macro for non-developer builds */
 #define SMB_ASSERT(b) do { if (!(b)) { \
@@ -61,9 +63,14 @@ extern const char *panic_action;
 #endif
 
 #if _SAMBA_BUILD_ == 4
-#if defined(VALGRIND)
+#ifdef VALGRIND
 #define strlen(x) valgrind_strlen(x)
+size_t valgrind_strlen(const char *s);
+#endif
 #endif
+
+#ifndef ABS
+#define ABS(a) ((a)>0?(a):(-(a)))
 #endif
 
 #include "../lib/util/memory.h"
@@ -119,9 +126,6 @@ void CatchChildLeaveStatus(void);
 
 /* The following definitions come from lib/util/system.c  */
 
-
-struct in_addr;
-
 /**************************************************************************
 A wrapper for gethostbyname() that tries avoids looking up hostnames 
 in the root domain, which can cause dial-on-demand links to come up for no
@@ -130,6 +134,16 @@ apparent reason.
 _PUBLIC_ struct hostent *sys_gethostbyname(const char *name);
 _PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host);
 
+/**
+ * Wrapper for fork used to invalid pid cache.
+ **/
+_PUBLIC_ pid_t sys_fork(void);
+
+/**
+ * Wrapper for getpid. Ensures we only do a system call *once*.
+ **/
+_PUBLIC_ pid_t sys_getpid(void);
+
 /* The following definitions come from lib/util/genrand.c  */
 
 /**
@@ -190,6 +204,21 @@ _PUBLIC_ void display_set_stderr(void);
 
 /* The following definitions come from lib/util/util_str.c  */
 
+bool next_token_talloc(TALLOC_CTX *ctx,
+                       const char **ptr,
+                       char **pp_buff,
+                       const char *sep);
+
+/**
+ * Get the next token from a string, return false if none found.  Handles
+ * double-quotes.  This version does not trim leading separator characters
+ * before looking for a token.
+ */
+bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx,
+                       const char **ptr,
+                       char **pp_buff,
+                       const char *sep);
+
 
 /**
  Trim the specified elements off the front and back of a string.
@@ -269,7 +298,6 @@ _PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, siz
  Unescape a URL encoded string, in place.
 **/
 _PUBLIC_ void rfc1738_unescape(char *buf);
-size_t valgrind_strlen(const char *s);
 
 /**
   format a string into length-prefixed dotted domain format, as used in NBT
@@ -533,9 +561,9 @@ _PUBLIC_ int set_blocking(int fd, bool set);
 _PUBLIC_ void msleep(unsigned int t);
 
 /**
- Get my own name, return in malloc'ed storage.
+ Get my own name, return in talloc'ed storage.
 **/
-_PUBLIC_ char* get_myname(void);
+_PUBLIC_ char* get_myname(TALLOC_CTX *mem_ctx);
 
 /**
  Return true if a string could be a pure IP address.
@@ -721,12 +749,15 @@ _PUBLIC_ int idr_remove(struct idr_context *idp, int id);
 
 /* The following definitions come from lib/util/become_daemon.c  */
 
-#if _SAMBA_BUILD_ == 4
+/**
+ Close the low 3 fd's and open dev/null in their place
+**/
+_PUBLIC_ void close_low_fds(bool stderr_too);
+
 /**
  Become a daemon, discarding the controlling terminal.
 **/
-_PUBLIC_ void become_daemon(bool fork);
-#endif
+_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group);
 
 /**
  * Load a ini-style file.