소스 검색

Provide own implementation of asprintf if it's missing.

master
Richard Nyberg 16 년 전
부모
커밋
7b8644dcc1
2개의 변경된 파일27개의 추가작업 그리고 1개의 파일을 삭제
  1. +20
    -0
      misc/subr.c
  2. +7
    -1
      misc/subr.h

+ 20
- 0
misc/subr.c 파일 보기

@@ -14,6 +14,8 @@
#include <strings.h> #include <strings.h>
#include <unistd.h> #include <unistd.h>


#include "subr.h"

void * void *
memfind(const void *sub, size_t sublen, const void *mem, size_t memlen) memfind(const void *sub, size_t sublen, const void *mem, size_t memlen)
{ {
@@ -443,3 +445,21 @@ end:
out[oi] = '\0'; out[oi] = '\0';
return 0; return 0;
} }

#ifndef HAVE_ASPRINTF
int
asprintf(char **strp, const char *fmt, ...)
{
int np;
va_list ap;
va_start(ap, fmt);
np = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
if ((*strp = malloc(np + 1)) == NULL)
return -1;
va_start(ap, fmt);
vsnprintf(*strp, np + 1, fmt, ap);
va_end(ap);
return np;
}
#endif

+ 7
- 1
misc/subr.h 파일 보기

@@ -1,8 +1,9 @@
#ifndef BTPD_SUBR_H #ifndef BTPD_SUBR_H
#define BTPD_SUBR_H #define BTPD_SUBR_H


#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <stdint.h>


#define max(x, y) ((x) >= (y) ? (x) : (y)) #define max(x, y) ((x) >= (y) ? (x) : (y))
#define min(x, y) ((x) <= (y) ? (x) : (y)) #define min(x, y) ((x) <= (y) ? (x) : (y))
@@ -47,4 +48,9 @@ void *read_file(const char *path, void *buf, size_t *size);
char *find_btpd_dir(void); char *find_btpd_dir(void);
int make_abs_path(const char *in, char *out); int make_abs_path(const char *in, char *out);


#ifndef HAVE_ASPRINTF
__attribute__((format (printf, 2, 3)))
int asprintf(char **strp, const char *fmt, ...);
#endif

#endif #endif

||||||
x
 
000:0
불러오는 중...
취소
저장