003 File Manager
Current Path:
/usr/src/contrib/ntp/sntp/libopts
usr
/
src
/
contrib
/
ntp
/
sntp
/
libopts
/
📁
..
📄
COPYING.gplv3
(34.34 KB)
📄
COPYING.lgplv3
(7.45 KB)
📄
COPYING.mbsd
(1.41 KB)
📄
MakeDefs.inc
(0 B)
📄
Makefile.am
(2.51 KB)
📄
Makefile.in
(27.52 KB)
📄
README
(4.84 KB)
📄
ag-char-map.h
(26.67 KB)
📄
alias.c
(3.26 KB)
📄
ao-strs.c
(13.82 KB)
📄
ao-strs.h
(14.02 KB)
📁
autoopts
📄
autoopts.c
(11.94 KB)
📄
autoopts.h
(12.96 KB)
📄
boolean.c
(2.45 KB)
📄
check.c
(4.84 KB)
📁
compat
📄
configfile.c
(35.76 KB)
📄
cook.c
(9.18 KB)
📄
enum.c
(18.09 KB)
📄
env.c
(7.17 KB)
📄
file.c
(5.67 KB)
📄
find.c
(22 KB)
📄
genshell.c
(30.64 KB)
📄
genshell.h
(7.77 KB)
📄
gettext.h
(9.79 KB)
📄
init.c
(8.42 KB)
📄
intprops.h
(14.58 KB)
📄
libopts.c
(1.06 KB)
📄
load.c
(15.98 KB)
📁
m4
📄
makeshell.c
(24.36 KB)
📄
nested.c
(24.33 KB)
📄
numeric.c
(5.05 KB)
📄
option-value-type.c
(5.5 KB)
📄
option-value-type.h
(2.36 KB)
📄
option-xat-attribute.c
(5.04 KB)
📄
option-xat-attribute.h
(2.25 KB)
📄
parse-duration.c
(12.11 KB)
📄
parse-duration.h
(3.32 KB)
📄
pgusage.c
(4.89 KB)
📄
proto.h
(2.73 KB)
📄
putshell.c
(14.62 KB)
📄
reset.c
(3.84 KB)
📄
restore.c
(6.82 KB)
📄
save.c
(20.53 KB)
📄
sort.c
(9.84 KB)
📄
stack.c
(7.23 KB)
📄
stdnoreturn.in.h
(1.77 KB)
📄
streqvcmp.c
(8.14 KB)
📄
text_mmap.c
(11.05 KB)
📄
time.c
(3.77 KB)
📄
tokenize.c
(8.99 KB)
📄
usage.c
(38.19 KB)
📄
version.c
(6.11 KB)
Editing: restore.c
/* * \file restore.c * * This module's routines will save the current option state to memory * and restore it. If saved prior to the initial optionProcess call, * then the initial state will be restored. * * @addtogroup autoopts * @{ */ /* * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. * AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control * of the user of the license. * * The GNU Lesser General Public License, version 3 or later * See the files "COPYING.lgplv3" and "COPYING.gplv3" * * The Modified Berkeley Software Distribution License * See the file "COPYING.mbsd" * * These files have the following sha256 sums: * * 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3 * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3 * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd */ /* * optionFixupSavedOpts Really, it just wipes out option state for * options that are troublesome to copy. viz., stacked strings and * hierarcicaly valued option args. We do duplicate string args that * have been marked as allocated though. */ static void fixupSavedOptionArgs(tOptions * pOpts) { tOptions * p = pOpts->pSavedState; tOptDesc * pOD = pOpts->pOptDesc; int ct = pOpts->optCt; /* * Make sure that allocated stuff is only referenced in the * archived copy of the data. */ for (; ct-- > 0; pOD++) { switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { case OPARG_TYPE_STRING: if (pOD->fOptState & OPTST_STACKED) { tOptDesc * q = p->pOptDesc + (pOD - pOpts->pOptDesc); q->optCookie = NULL; } if (pOD->fOptState & OPTST_ALLOC_ARG) { tOptDesc * q = p->pOptDesc + (pOD - pOpts->pOptDesc); AGDUPSTR(q->optArg.argString, pOD->optArg.argString, "arg"); } break; case OPARG_TYPE_HIERARCHY: { tOptDesc * q = p->pOptDesc + (pOD - pOpts->pOptDesc); q->optCookie = NULL; } } } } /*=export_func optionSaveState * * what: saves the option state to memory * arg: tOptions *, pOpts, program options descriptor * * doc: * * This routine will allocate enough memory to save the current option * processing state. If this routine has been called before, that memory * will be reused. You may only save one copy of the option state. This * routine may be called before optionProcess(3AO). If you do call it * before the first call to optionProcess, then you may also change the * contents of argc/argv after you call optionRestore(3AO) * * In fact, more strongly put: it is safest to only use this function * before having processed any options. In particular, the saving and * restoring of stacked string arguments and hierarchical values is * disabled. The values are not saved. * * err: If it fails to allocate the memory, * it will print a message to stderr and exit. * Otherwise, it will always succeed. =*/ void optionSaveState(tOptions * pOpts) { tOptions * p = (tOptions *)pOpts->pSavedState; if (p == NULL) { size_t sz = sizeof(*pOpts) + ((size_t)pOpts->optCt * sizeof(tOptDesc)); p = AGALOC(sz, "saved option state"); pOpts->pSavedState = p; } memcpy(p, pOpts, sizeof(*p)); memcpy(p + 1, pOpts->pOptDesc, (size_t)p->optCt * sizeof(tOptDesc)); fixupSavedOptionArgs(pOpts); } /*=export_func optionRestore * * what: restore option state from memory copy * arg: tOptions *, pOpts, program options descriptor * * doc: Copy back the option state from saved memory. * The allocated memory is left intact, so this routine can be * called repeatedly without having to call optionSaveState again. * If you are restoring a state that was saved before the first call * to optionProcess(3AO), then you may change the contents of the * argc/argv parameters to optionProcess. * * err: If you have not called @code{optionSaveState} before, a diagnostic is * printed to @code{stderr} and exit is called. =*/ void optionRestore(tOptions * pOpts) { tOptions * p = (tOptions *)pOpts->pSavedState; if (p == NULL) { char const * pzName = pOpts->pzProgName; if (pzName == NULL) { pzName = pOpts->pzPROGNAME; if (pzName == NULL) pzName = zNil; } fprintf(stderr, zNoState, pzName); option_exits(EXIT_FAILURE); } pOpts->pSavedState = NULL; optionFree(pOpts); memcpy(pOpts, p, sizeof(*p)); memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc)); pOpts->pSavedState = p; fixupSavedOptionArgs(pOpts); } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /*=export_func optionFree * * what: free allocated option processing memory * arg: tOptions *, pOpts, program options descriptor * * doc: AutoOpts sometimes allocates memory and puts pointers to it in the * option state structures. This routine deallocates all such memory. * * err: As long as memory has not been corrupted, * this routine is always successful. =*/ void optionFree(tOptions * pOpts) { free_saved_state: { tOptDesc * p = pOpts->pOptDesc; int ct = pOpts->optCt; do { if (p->fOptState & OPTST_ALLOC_ARG) { AGFREE(p->optArg.argString); p->optArg.argString = NULL; p->fOptState &= ~OPTST_ALLOC_ARG; } switch (OPTST_GET_ARGTYPE(p->fOptState)) { case OPARG_TYPE_STRING: #ifdef WITH_LIBREGEX if ( (p->fOptState & OPTST_STACKED) && (p->optCookie != NULL)) { p->optArg.argString = ".*"; optionUnstackArg(pOpts, p); } #else /* leak memory */; #endif break; case OPARG_TYPE_HIERARCHY: if (p->optCookie != NULL) unload_arg_list(p->optCookie); break; } p->optCookie = NULL; } while (p++, --ct > 0); } if (pOpts->pSavedState != NULL) { tOptions * p = (tOptions *)pOpts->pSavedState; memcpy(pOpts, p, sizeof(*p)); memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc)); AGFREE(pOpts->pSavedState); pOpts->pSavedState = NULL; goto free_saved_state; } } /** @} * * Local Variables: * mode: C * c-file-style: "stroustrup" * indent-tabs-mode: nil * End: * end of autoopts/restore.c */
Upload File
Create Folder