Home | History | Annotate | Download | only in src
      1 /*
      2  * util.h - routeup/tlsdated utility functions
      3  * Copyright (c) 2012 The Chromium Authors. All rights reserved.
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef UTIL_H
      9 #define UTIL_H
     10 
     11 #include <errno.h>
     12 #include <string.h>
     13 #include <stdlib.h>
     14 
     15 #if _PLAN9_SOURCE
     16 #define API
     17 #else
     18 #define API __attribute__((visibility("default")))
     19 #endif
     20 
     21 extern int verbose;
     22 extern int verbose_debug;
     23 void die (const char *fmt, ...);
     24 void verb (const char *fmt, ...);
     25 extern void logat(int isverbose, const char *fmt, ...);
     26 
     27 #define info(fmt, ...) logat(1, fmt, ## __VA_ARGS__)
     28 #define pinfo(fmt, ...) logat(1, fmt ": %s", ## __VA_ARGS__, strerror(errno))
     29 #define error(fmt, ...) logat(0, fmt, ## __VA_ARGS__)
     30 #define perror(fmt, ...) logat(0, fmt ": %s", ## __VA_ARGS__, strerror(errno))
     31 #define fatal(fmt, ...) do { logat(0, fmt, ## __VA_ARGS__); exit(1); } while (0)
     32 #define pfatal(fmt, ...) do { \
     33   logat(0, fmt ": %s", ## __VA_ARGS__, strerror(errno)); \
     34   exit(1); \
     35 } while (0)
     36 
     37 static inline int min(int x, int y) { return x < y ? x : y; }
     38 
     39 void drop_privs_to (const char *user, const char *group,
     40                     const char **supp_groups);
     41 
     42 #endif /* !UTIL_H */
     43