asprintf.c (e74101e4eff767325553039def89de70b70f36d3) asprintf.c (6879bea818b8bbf6d3b89560fb6b151a52eed368)
1/* $OpenBSD: asprintf.c,v 1.4 1998/06/21 22:13:46 millert Exp $ */
2
3/*
4 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 40 unchanged lines hidden (view full) ---

49 f._file = -1;
50 f._flags = __SWR | __SSTR | __SALC;
51 f._bf._base = f._p = (unsigned char *)malloc(128);
52 if (f._bf._base == NULL) {
53 *str = NULL;
54 errno = ENOMEM;
55 return (-1);
56 }
1/* $OpenBSD: asprintf.c,v 1.4 1998/06/21 22:13:46 millert Exp $ */
2
3/*
4 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 40 unchanged lines hidden (view full) ---

49 f._file = -1;
50 f._flags = __SWR | __SSTR | __SALC;
51 f._bf._base = f._p = (unsigned char *)malloc(128);
52 if (f._bf._base == NULL) {
53 *str = NULL;
54 errno = ENOMEM;
55 return (-1);
56 }
57 f._bf._size = f._w = 127; /* Leave room for the NULL */
57 f._bf._size = f._w = 127; /* Leave room for the NUL */
58 f._extra = &ext;
59 INITEXTRA(&f);
60 ret = __vfprintf(&f, fmt, ap); /* Use unlocked __vfprintf */
61 *f._p = '\0';
62 va_end(ap);
63 f._bf._base = reallocf(f._bf._base, f._bf._size + 1);
64 if (f._bf._base == NULL) {
65 errno = ENOMEM;
66 ret = -1;
67 }
68 *str = (char *)f._bf._base;
69 return (ret);
70}
58 f._extra = &ext;
59 INITEXTRA(&f);
60 ret = __vfprintf(&f, fmt, ap); /* Use unlocked __vfprintf */
61 *f._p = '\0';
62 va_end(ap);
63 f._bf._base = reallocf(f._bf._base, f._bf._size + 1);
64 if (f._bf._base == NULL) {
65 errno = ENOMEM;
66 ret = -1;
67 }
68 *str = (char *)f._bf._base;
69 return (ret);
70}