Pārlūkot izejas kodu

libdpkg: Add new m_asprintf() function

Guillem Jover 15 gadi atpakaļ
vecāks
revīzija
38a86e06fd
3 mainītis faili ar 20 papildinājumiem un 0 dzēšanām
  1. 1 0
      lib/dpkg/dpkg.h
  2. 1 0
      lib/dpkg/libdpkg.Versions
  3. 18 0
      lib/dpkg/mlib.c

+ 1 - 0
lib/dpkg/dpkg.h

@@ -137,6 +137,7 @@ void setcloexec(int fd, const char* fn);
 void *m_malloc(size_t);
 void *m_realloc(void*, size_t);
 char *m_strdup(const char *str);
+int m_asprintf(char **strp, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
 void m_dup2(int oldfd, int newfd);
 void m_pipe(int fds[2]);
 void m_output(FILE *f, const char *name);

+ 1 - 0
lib/dpkg/libdpkg.Versions

@@ -38,6 +38,7 @@ LIBDPKG_PRIVATE {
 	m_malloc;
 	m_realloc;
 	m_strdup;
+	m_asprintf;
 	m_dup2;
 	m_pipe;
 	m_output;

+ 18 - 0
lib/dpkg/mlib.c

@@ -73,6 +73,24 @@ m_strdup(const char *str)
   return new_str;
 }
 
+int
+m_asprintf(char **strp, const char *fmt, ...)
+{
+  va_list args;
+  int n;
+
+  va_start(args, fmt);
+  n = vasprintf(strp, fmt, args);
+  va_end(args);
+
+  onerr_abort++;
+  if (n < 0)
+    ohshite(_("failed to allocate memory"));
+  onerr_abort--;
+
+  return n;
+}
+
 void m_dup2(int oldfd, int newfd) {
   const char *const stdstrings[]= { "in", "out", "err" };