struct netent *getnetent(void) { char *p; register char *cp, **q; struct netent *rv = NULL; __UCLIBC_MUTEX_LOCK(mylock); if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) { goto DONE; } again: if (!line) { line = malloc(BUFSIZ + 1); if (!line) abort(); } p = fgets(line, BUFSIZ, netf); if (p == NULL) { goto DONE; } if (*p == '#') goto again; cp = any(p, "#\n"); if (cp == NULL) goto again; *cp = '\0'; net.n_name = p; cp = any(p, " \t"); if (cp == NULL) goto again; *cp++ = '\0'; while (*cp == ' ' || *cp == '\t') cp++; p = any(cp, " \t"); if (p != NULL) *p++ = '\0'; net.n_net = inet_network(cp); net.n_addrtype = AF_INET; q = net.n_aliases = net_aliases; if (p != NULL) cp = p; while (cp && *cp) { if (*cp == ' ' || *cp == '\t') { cp++; continue; } if (q < &net_aliases[MAXALIASES - 1]) *q++ = cp; cp = any(cp, " \t"); if (cp != NULL) *cp++ = '\0'; } *q = NULL; rv = &net; DONE: __UCLIBC_MUTEX_UNLOCK(mylock); return rv; }
void setutent(void) { int ret; __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd == -1) { if ((static_fd = open(static_ut_name, O_RDWR)) < 0) { if ((static_fd = open(static_ut_name, O_RDONLY)) < 0) { goto bummer; } } /* Make sure the file will be closed on exec() */ ret = fcntl(static_fd, F_GETFD, 0); if (ret >= 0) { ret = fcntl(static_fd, F_GETFD, 0); } if (ret < 0) { bummer: close(static_fd); static_fd = -1; goto DONE; } } lseek(static_fd, 0, SEEK_SET); DONE: __UCLIBC_MUTEX_UNLOCK(utmplock); return; }
/* libc_hidden_proto(getservbyname_r) */ int getservbyname_r(const char *name, const char *proto, struct servent * result_buf, char * buf, size_t buflen, struct servent ** result) { register char **cp; int ret; __UCLIBC_MUTEX_LOCK(mylock); setservent(serv_stayopen); while (!(ret=getservent_r(result_buf, buf, buflen, result))) { if (strcmp(name, result_buf->s_name) == 0) goto gotname; for (cp = result_buf->s_aliases; *cp; cp++) if (strcmp(name, *cp) == 0) goto gotname; continue; gotname: if (proto == 0 || strcmp(result_buf->s_proto, proto) == 0) break; } if (!serv_stayopen) endservent(); __UCLIBC_MUTEX_UNLOCK(mylock); return *result?0:ret; }
/* * Find and return a new exit_function pointer, for atexit, * onexit and __cxa_atexit to initialize */ struct exit_function attribute_hidden *__new_exitfn(void) { struct exit_function *efp; __UCLIBC_MUTEX_LOCK(__atexit_lock); #ifdef __UCLIBC_DYNAMIC_ATEXIT__ /* If we are out of function table slots, make some more */ if (__exit_slots < __exit_count+1) { efp=realloc(__exit_function_table, (__exit_slots+20)*sizeof(struct exit_function)); if (efp == NULL) { __set_errno(ENOMEM); goto DONE; } __exit_function_table = efp; __exit_slots += 20; } #else if (__exit_count >= __UCLIBC_MAX_ATEXIT) { __set_errno(ENOMEM); efp = NULL; goto DONE; } #endif __exit_cleanup = __exit_handler; /* enable cleanup */ efp = &__exit_function_table[__exit_count++]; efp->type = ef_in_use; DONE: __UCLIBC_MUTEX_UNLOCK(__atexit_lock); return efp; }
int unsetenv (const char *name) { size_t len; char **ep; if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { __set_errno (EINVAL); return -1; } len = strlen (name); __UCLIBC_MUTEX_LOCK(mylock); ep = __environ; while (*ep != NULL) { if (!strncmp (*ep, name, len) && (*ep)[len] == '=') { /* Found it. Remove this pointer by moving later ones back. */ char **dp = ep; do { dp[0] = dp[1]; } while (*dp++); /* Continue the loop in case NAME appears again. */ } else { ++ep; } } __UCLIBC_MUTEX_UNLOCK(mylock); return 0; }
void endutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd != -1) close(static_fd); static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); }
void end(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd >= 0) close_not_cancel_no_status(static_fd); static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); }
struct utmp *getutid(const struct utmp *utmp_entry) { struct utmp *ret = NULL; __UCLIBC_MUTEX_LOCK(utmplock); ret = __getutid(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; }
long int random (void) { int32_t retval; __UCLIBC_MUTEX_LOCK(mylock); random_r (&unsafe_state, &retval); __UCLIBC_MUTEX_UNLOCK(mylock); return retval; }
int getrpcent_r(struct rpcent *result_buf, char *buffer, size_t buflen, struct rpcent **result) { int ret; __UCLIBC_MUTEX_LOCK(mylock); ret = __copy_rpcent(getrpcent(), result_buf, buffer, buflen, result); __UCLIBC_MUTEX_UNLOCK(mylock); return ret; }
struct UT *get(void) { struct UT *ret; __UCLIBC_MUTEX_LOCK(utmplock); ret = __get_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; }
struct utmp *getutent(void) { struct utmp *ret = NULL; __UCLIBC_MUTEX_LOCK(utmplock); ret = __getutent(static_fd); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; }
struct UT *getid(const struct UT *utmp_entry) { struct UT *ret; __UCLIBC_MUTEX_LOCK(utmplock); ret = __getid_unlocked(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; }
void endnetent(void) { __UCLIBC_MUTEX_LOCK(mylock); if (netf) { fclose(netf); netf = NULL; } _net_stayopen = 0; __UCLIBC_MUTEX_UNLOCK(mylock); }
/* Initialize the state information in the given array of N bytes for future random number generation. Based on the number of bytes we are given, and the break values for the different R.N.G.'s, we choose the best (largest) one we can and set things up for it. srandom is then called to initialize the state information. Note that on return from srandom, we set state[-1] to be the type multiplexed with the current value of the rear pointer; this is so successive calls to initstate won't lose this information and will be able to restart with setstate. Note: The first thing we do is save the current state, if any, just like setstate so that it doesn't matter when initstate is called. Returns a pointer to the old state. */ char * initstate (unsigned int seed, char *arg_state, size_t n) { int32_t *ostate; __UCLIBC_MUTEX_LOCK(mylock); ostate = &unsafe_state.state[-1]; initstate_r (seed, arg_state, n, &unsafe_state); __UCLIBC_MUTEX_UNLOCK(mylock); return (char *) ostate; }
void endprotoent(void) { __UCLIBC_MUTEX_LOCK(mylock); if (protof) { fclose(protof); protof = NULL; } proto_stayopen = 0; __UCLIBC_MUTEX_UNLOCK(mylock); }
/* libc_hidden_proto(setservent) */ void setservent(int f) { __UCLIBC_MUTEX_LOCK(mylock); if (servf == NULL) servf = fopen(_PATH_SERVICES, "r" ); else rewind(servf); if (f) serv_stayopen = 1; __UCLIBC_MUTEX_UNLOCK(mylock); }
void setprotoent(int f) { __UCLIBC_MUTEX_LOCK(mylock); if (protof == NULL) protof = fopen(_PATH_PROTOCOLS, "r" ); else rewind(protof); if (f) proto_stayopen = 1; __UCLIBC_MUTEX_UNLOCK(mylock); }
/* libc_hidden_proto(endservent) */ void endservent(void) { __UCLIBC_MUTEX_LOCK(mylock); if (servf) { fclose(servf); servf = NULL; } serv_stayopen = 0; __UCLIBC_MUTEX_UNLOCK(mylock); }
void setservent(int stayopen) { __UCLIBC_MUTEX_LOCK(mylock); if (servp) config_close(servp); servp = config_open(_PATH_SERVICES); if (stayopen) serv_stayopen = 1; __UCLIBC_MUTEX_UNLOCK(mylock); }
void endservent(void) { __UCLIBC_MUTEX_LOCK(mylock); if (servp) { config_close(servp); servp = NULL; } serv_stayopen = 0; __UCLIBC_MUTEX_UNLOCK(mylock); }
/* setlogmask -- set the log mask level */ int setlogmask(int pmask) { int omask; omask = LogMask; __UCLIBC_MUTEX_LOCK(mylock); if (pmask != 0) LogMask = pmask; __UCLIBC_MUTEX_UNLOCK(mylock); return (omask); }
/* Restore the state from the given state array. Note: It is important that we also remember the locations of the pointers in the current state information, and restore the locations of the pointers from the old state information. This is done by multiplexing the pointer location into the zeroth word of the state information. Note that due to the order in which things are done, it is OK to call setstate with the same state as the current state Returns a pointer to the old state information. */ char * setstate (char *arg_state) { int32_t *ostate; __UCLIBC_MUTEX_LOCK(mylock); ostate = &unsafe_state.state[-1]; if (setstate_r (arg_state, &unsafe_state) < 0) ostate = NULL; __UCLIBC_MUTEX_UNLOCK(mylock); return (char *) ostate; }
/* rewinddir() just does an lseek(fd,0,0) - see close for comments */ void rewinddir(DIR * dir) { if (!dir) { __set_errno(EBADF); return; } __UCLIBC_MUTEX_LOCK(dir->dd_lock); lseek(dir->dd_fd, 0, SEEK_SET); dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0; __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); }
void setnetent(int f) { __UCLIBC_MUTEX_LOCK(mylock); if (netf == NULL) netf = fopen(NETDB, "r" ); else rewind(netf); _net_stayopen |= f; __UCLIBC_MUTEX_UNLOCK(mylock); return; }
/* The `clearenv' was planned to be added to POSIX.1 but probably never made it. Nevertheless the POSIX.9 standard (POSIX bindings for Fortran 77) requires this function. */ int clearenv (void) { __UCLIBC_MUTEX_LOCK(mylock); if (__environ == last_environ && __environ != NULL) { /* We allocated this environment so we can free it. */ free (__environ); last_environ = NULL; } /* Clear the environment pointer removes the whole environment. */ __environ = NULL; __UCLIBC_MUTEX_UNLOCK(mylock); return 0; }
struct utmp *getutline(const struct utmp *utmp_entry) { struct utmp *lutmp = NULL; __UCLIBC_MUTEX_LOCK(utmplock); while ((lutmp = __getutent(static_fd)) != NULL) { if ((lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) && !strcmp(lutmp->ut_line, utmp_entry->ut_line)) { break; } } __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; }
/* * OPENLOG -- open system log */ void openlog( const char *ident, int logstat, int logfac ) { int logType = SOCK_DGRAM; __UCLIBC_MUTEX_LOCK(mylock); if (ident != NULL) LogTag = ident; LogStat = logstat; if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) LogFacility = logfac; if (LogFile == -1) { SyslogAddr.sun_family = AF_UNIX; (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, sizeof(SyslogAddr.sun_path)); if (strlen(_PATH_LOG) > sizeof(SyslogAddr.sun_path)) SyslogAddr.sun_path[sizeof(SyslogAddr.sun_path) - 1] = '\0'; retry: if (LogStat & LOG_NDELAY) { if ((LogFile = socket(AF_UNIX, logType, 0)) == -1) { goto DONE; } fcntl(LogFile, F_SETFD, 1); fcntl(LogFile, F_SETFL, O_NONBLOCK); } } if (LogFile != -1 && !connected) { if (connect(LogFile, &SyslogAddr, SUN_LEN(&SyslogAddr)) != -1) { connected = 1; } else if (logType == SOCK_DGRAM) { logType = SOCK_STREAM; if (LogFile != -1) { close(LogFile); LogFile = -1; } goto retry; } else { if (LogFile != -1) { close(LogFile); LogFile = -1; } } } DONE: __UCLIBC_MUTEX_UNLOCK(mylock); }
int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result) { int ret; ssize_t bytes; struct dirent *de; if (!dir) { __set_errno(EBADF); return(EBADF); } de = NULL; __UCLIBC_MUTEX_LOCK(dir->dd_lock); do { if (dir->dd_size <= dir->dd_nextloc) { /* read dir->dd_max bytes of directory entries. */ bytes = __getdents(dir->dd_fd, dir->dd_buf, dir->dd_max); if (bytes <= 0) { *result = NULL; ret = (bytes==0)? 0 : errno; goto all_done; } dir->dd_size = bytes; dir->dd_nextloc = 0; } de = (struct dirent *) (((char *) dir->dd_buf) + dir->dd_nextloc); /* Am I right? H.J. */ dir->dd_nextloc += de->d_reclen; /* We have to save the next offset here. */ dir->dd_nextoff = de->d_off; /* Skip deleted files. */ } while (de->d_ino == 0); if (de == NULL) { *result = NULL; } else { *result = memcpy (entry, de, de->d_reclen); } ret = 0; all_done: __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); return((de != NULL)? 0 : ret); }
struct UT *getline(const struct UT *utmp_entry) { struct UT *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); while ((lutmp = __get_unlocked()) != NULL) { if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { break; } } } __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; }