char *acl_default_strndup(const char *filename, int line, const char *str, size_t len) { const char *myname = "acl_default_strndup"; char *result; char *cp; const char *pname = NULL; if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; if (str == 0) acl_msg_fatal("%s(%d)->%s: null pointer argument", pname, line, myname); #ifndef NO_SHARED_EMPTY_STRINGS if (*str == 0) return ((char *) empty_string); #endif if ((cp = memchr(str, 0, len)) != 0) len = cp - str; result = memcpy(acl_default_malloc(pname, line, len + 1), str, len); result[len] = 0; return (result); }
void acl_default_free(const char *filename, int line, void *ptr) { const char *myname = "acl_default_free"; MBLOCK *real_ptr; size_t len; const char *pname = NULL; if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; if (ptr == NULL) { acl_msg_error("%s(%d)->%s: ptr null", pname, line, myname); return; } # ifndef NO_SHARED_EMPTY_STRINGS if (ptr != empty_string) { # endif CHECK_IN_PTR(ptr, real_ptr, len, pname, line); /* memset((char *) real_ptr, FILLER, SPACE_FOR(len)); */ #ifdef _USE_GLIB g_free(real_ptr); #else free((char *) real_ptr); #endif # ifndef NO_SHARED_EMPTY_STRINGS } # endif }
static FILE * _endopen(const char *file, const char *mode, FILE *iop, int largefile) { int plus, oflag, fd; if (iop == NULL || file == NULL || file[0] == '\0') return (NULL); plus = (mode[1] == '+'); switch (mode[0]) { case 'w': oflag = (plus ? O_RDWR : O_WRONLY) | O_TRUNC | O_CREAT; break; case 'a': oflag = (plus ? O_RDWR : O_WRONLY) | O_CREAT; break; case 'r': oflag = plus ? O_RDWR : O_RDONLY; break; default: return (NULL); } if (largefile) { fd = open64(file, oflag, 0666); /* mapped to open() for V9 */ } else { fd = open(file, oflag, 0666); } if (fd < 0) return (NULL); iop->_cnt = 0; #ifdef _LP64 iop->_file = fd; #else if (fd <= _FILE_FD_MAX) { SET_FILE(iop, fd); } else if (_file_set(iop, fd, mode) != 0) { /* errno set in _file_set() */ (void) close(fd); return (NULL); } #endif iop->_flag = plus ? _IORW : (mode[0] == 'r') ? _IOREAD : _IOWRT; if (mode[0] == 'a') { if ((lseek64(fd, 0L, SEEK_END)) < 0) { (void) close(fd); return (NULL); } } iop->_base = iop->_ptr = NULL; /* * Sys5 does not support _bufsiz * * iop->_bufsiz = 0; */ return (iop); }
void *acl_default_realloc(const char *filename, int line, void *ptr, size_t len) { const char *myname = "acl_default_realloc"; MBLOCK *real_ptr; size_t old_len, new_len; const char *pname = NULL; if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; #ifndef NO_SHARED_EMPTY_STRINGS if (ptr == empty_string) return acl_default_malloc(pname, line, len); #endif if (len < 1) { acl_msg_warn("%s(%d)->%s: realloc: requested length %ld", pname, line, myname, (long) len); len = 128; } if (ptr == NULL) return acl_default_malloc(pname, line, len); CHECK_IN_PTR(ptr, real_ptr, old_len, pname, line); new_len = SPACE_FOR(len); if (new_len <= 0) acl_msg_fatal("%s(%d): new_len(%d) <= 0", myname, __LINE__, (int) new_len); else if (new_len >= __malloc_limit) { acl_msg_warn("%s(%d): new_len(%d) too large", myname, __LINE__, (int) new_len); } #ifdef _USE_GLIB if ((real_ptr = (MBLOCK *) g_realloc((char *) real_ptr, new_len)) == 0) acl_msg_fatal("%s(%d)->%s: realloc: insufficient memory: %s", pname, line, myname, strerror(errno)); #else if ((real_ptr = (MBLOCK *) realloc((char *) real_ptr, new_len)) == 0) acl_msg_fatal("%s(%d)->%s: realloc: insufficient memory: %s", pname, line, myname, strerror(errno)); #endif CHECK_OUT_PTR(ptr, real_ptr, len); #if 0 if (len > old_len) memset((char *) ptr + old_len, FILLER, len - old_len); #endif return ptr; }
void *acl_default_malloc(const char *filename, int line, size_t len) { const char *myname = "acl_default_malloc"; size_t new_len; char *ptr; MBLOCK *real_ptr; const char *pname = NULL; #if 0 printf("%s:%d, len: %d\r\n", filename, line, (int) len); acl_trace_info(); #endif if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; if (len < 1) { acl_msg_warn("%s(%d), %s: malloc: length %ld invalid", pname, line, myname, (long) len); len = 128; } new_len = SPACE_FOR(len); if (new_len <= 0) acl_msg_fatal("%s(%d): new_len(%d) <= 0", myname, __LINE__, (int) new_len); else if (new_len >= __malloc_limit) { acl_msg_warn("%s(%d): new_len(%d) too large", myname, __LINE__, (int) new_len); } #ifdef _USE_GLIB if ((real_ptr = (MBLOCK *) g_malloc(new_len)) == 0) { acl_msg_error("%s(%d)->%s: new_len: %d, g_malloc error(%s)", pname, line, myname, (int) new_len, strerror(errno)); return 0; } #else if ((real_ptr = (MBLOCK *) malloc(new_len)) == 0) { acl_msg_error("%s(%d)->%s: malloc: insufficient memory: %s, " "new_len: %d", pname, line, myname, strerror(errno), (int) new_len); return 0; } #endif CHECK_OUT_PTR(ptr, real_ptr, len); #if 0 memset(ptr, FILLER, len); #endif return ptr; }
FILE * fdopen(int fd, const char *type) /* associate file desc. with stream */ { /* iop doesn't need locking since this function is creating it */ FILE *iop; char plus; unsigned char flag; /* Sets EBADF for bad fds */ if (fcntl(fd, F_GETFD) == -1) return (NULL); if ((iop = _findiop()) == 0) { errno = ENOMEM; return (NULL); } switch (type[0]) { default: iop->_flag = 0; /* release iop */ errno = EINVAL; return (NULL); case 'r': flag = _IOREAD; break; case 'a': (void) lseek64(fd, (off64_t)0, SEEK_END); /*FALLTHROUGH*/ case 'w': flag = _IOWRT; break; } if ((plus = type[1]) == 'b') /* Unix ignores 'b' ANSI std */ plus = type[2]; if (plus == '+') flag = _IORW; iop->_flag = flag; #ifdef _LP64 iop->_file = fd; #else if (fd <= _FILE_FD_MAX) { SET_FILE(iop, fd); } else if (_file_set(iop, fd, type) != 0) { /* errno set by _file_set () */ iop->_flag = 0; /* release iop */ return (NULL); } #endif /* _LP64 */ return (iop); }
void *acl_default_memdup(const char *filename, int line, const void *ptr, size_t len) { const char *myname = "acl_default_memdup"; const char *pname = NULL; if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; if (ptr == 0) acl_msg_fatal("%s(%d)->%s: null pointer argument", pname, line, myname); return (memcpy(acl_default_malloc(pname, line, len), ptr, len)); }
void acl_default_memstat(const char *filename, int line, void *ptr, size_t *len, size_t *real_len) { MBLOCK *real_ptr; const char *pname = NULL; size_t old_len; if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; CHECK_PTR(ptr, real_ptr, old_len, pname, line); if (len) *len = real_ptr->length; if (real_len) *real_len = SPACE_FOR(*len); }
static apr_status_t vt_gdbm_open(apr_dbm_t **pdb, const char *pathname, apr_int32_t mode, apr_fileperms_t perm, apr_pool_t *pool) { real_file_t file; int dbmode; *pdb = NULL; switch (mode) { case APR_DBM_READONLY: dbmode = APR_DBM_DBMODE_RO; break; case APR_DBM_READWRITE: dbmode = APR_DBM_DBMODE_RW; break; case APR_DBM_RWCREATE: dbmode = APR_DBM_DBMODE_RWCREATE; break; case APR_DBM_RWTRUNC: dbmode = APR_DBM_DBMODE_RWTRUNC; break; default: return APR_EINVAL; } { /* Note: stupid cast to get rid of "const" on the pathname */ file = gdbm_open((char *) pathname, 0, dbmode, apr_posix_perms2mode(perm), NULL); if (file == NULL) return APR_EGENERAL; /* ### need a better error */ } /* we have an open database... return it */ *pdb = apr_pcalloc(pool, sizeof(**pdb)); (*pdb)->pool = pool; (*pdb)->type = &apr_dbm_type_gdbm; SET_FILE(*pdb, file); /* ### register a cleanup to close the DBM? */ return APR_SUCCESS; }
void *acl_default_malloc(const char *filename, int line, size_t len) { const char *myname = "acl_default_malloc"; size_t new_len; char *ptr; MBLOCK *real_ptr; const char *pname = NULL; if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; if (len < 1) acl_msg_fatal("%s(%d)->%s: malloc: requested length %ld invalid", pname, line, myname, (long) len); new_len = SPACE_FOR(len); if (new_len <= 0) acl_msg_fatal("%s(%d): new_len(%d) <= 0", myname, __LINE__, (int) new_len); else if (new_len >= 100000000) acl_msg_warn("%s(%d): new_len(%d) too large", myname, __LINE__, (int) new_len); #ifdef _USE_GLIB if ((real_ptr = (MBLOCK *) g_malloc(new_len)) == 0) { acl_msg_error("%s(%d)->%s: g_malloc error(%s)", pname, line, myname, strerror(errno)); return (0); } #else if ((real_ptr = (MBLOCK *) malloc(new_len)) == 0) { acl_msg_error("%s(%d)->%s: malloc: insufficient memory: %s", pname, line, myname, strerror(errno)); return (0); } #endif CHECK_OUT_PTR(ptr, real_ptr, len); #if 0 memset(ptr, FILLER, len); #endif return (ptr); }
vswscanf(const wchar_t *wstr, const wchar_t *fmt, va_list ap) #endif { FILE strbuf; size_t wlen, clen; char *tmp_buf; int ret; /* * The dummy FILE * created for swscanf has the _IOWRT * flag set to distinguish it from wscanf and fwscanf * invocations. */ clen = wcstombs(NULL, wstr, 0); if (clen == (size_t)-1) { errno = EILSEQ; return (EOF); } tmp_buf = alloca(sizeof (char) * (clen + 1)); if (tmp_buf == NULL) return (EOF); wlen = wcstombs(tmp_buf, wstr, clen + 1); if (wlen == (size_t)-1) { errno = EILSEQ; return (EOF); } strbuf._flag = _IOREAD | _IOWRT; strbuf._ptr = strbuf._base = (unsigned char *)tmp_buf; strbuf._cnt = strlen(tmp_buf); SET_FILE(&strbuf, _NFILE); /* Probably the following is not required. */ /* _setorientation(&strbuf, _WC_MODE); */ #ifdef _C89_INTMAX32 ret = __wdoscan_u(&strbuf, fmt, ap, _F_INTMAX32); #else ret = __wdoscan_u(&strbuf, fmt, ap, 0); #endif return (ret); }
char *acl_default_strdup(const char *filename, int line, const char *str) { const char *myname = "acl_default_strdup"; const char *pname = NULL; if (filename && *filename) SET_FILE(pname, filename); else pname = __FILENAME_UNKNOWN; if (str == 0) acl_msg_fatal("%s(%d)->%s: null pointer argument", pname, line, myname); #ifndef NO_SHARED_EMPTY_STRINGS if (*str == 0) return ((char *) empty_string); #endif return (strcpy(acl_default_malloc(pname, line, strlen(str) + 1), str)); }
FILE * _endopen(const char *name, const char *type, FILE *iop, int largefile) { int oflag, fd, fflag, eflag, plusflag, xflag; const char *echr; if (iop == NULL) return (NULL); switch (type[0]) { default: errno = EINVAL; return (NULL); case 'r': oflag = O_RDONLY; fflag = _IOREAD; break; case 'w': oflag = O_WRONLY | O_TRUNC | O_CREAT; fflag = _IOWRT; break; case 'a': oflag = O_WRONLY | O_APPEND | O_CREAT; fflag = _IOWRT; break; } plusflag = 0; eflag = 0; xflag = 0; for (echr = type + 1; *echr != '\0'; echr++) { switch (*echr) { /* UNIX ignores 'b' and treats text and binary the same */ default: break; case '+': plusflag = 1; break; case 'e': eflag = 1; break; case 'x': xflag = 1; break; } } if (eflag) { /* Subsequent to a mode flag, 'e' indicates O_CLOEXEC */ oflag = oflag | O_CLOEXEC; } if (plusflag) { oflag = (oflag & ~(O_RDONLY | O_WRONLY)) | O_RDWR; fflag = _IORW; } if (xflag) { oflag |= O_EXCL; } /* select small or large file open based on flag */ if (largefile) { fd = open64(name, oflag, 0666); } else { fd = open(name, oflag, 0666); } if (fd < 0) return (NULL); /* As long as we make sure _flag stays != 0, we don't need to lock */ #ifdef _LP64 iop->_file = fd; iop->_flag = (iop->_flag & ~0377) | fflag; #else if (fd <= _FILE_FD_MAX) { SET_FILE(iop, fd); } else if (_file_set(iop, fd, type) != 0) { /* errno set in _file_set() */ (void) close(fd); return (NULL); } iop->_flag = fflag; #endif /* _LP64 */ if (oflag == (O_WRONLY | O_APPEND | O_CREAT)) { /* type == "a" */ if (lseek64(fd, (off64_t)0, SEEK_END) < (off64_t)0) { (void) close(fd); return (NULL); } } return (iop); }