mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-10-14 02:22:03 +08:00
updated libopts
This commit is contained in:
+20
-25
@@ -2,15 +2,17 @@
|
||||
/*
|
||||
* \file restore.c
|
||||
*
|
||||
* Time-stamp: "2010-08-22 11:04:00 bkorb"
|
||||
*
|
||||
* 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-2012 by Bruce Korb - all rights reserved
|
||||
* AutoOpts is Copyright (C) 1992-2013 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
|
||||
@@ -22,11 +24,11 @@
|
||||
* The Modified Berkeley Software Distribution License
|
||||
* See the file "COPYING.mbsd"
|
||||
*
|
||||
* These files have the following md5sums:
|
||||
* These files have the following sha256 sums:
|
||||
*
|
||||
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
|
||||
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
|
||||
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
|
||||
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
|
||||
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
|
||||
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -92,29 +94,20 @@ fixupSavedOptionArgs(tOptions* pOpts)
|
||||
* Otherwise, it will always succeed.
|
||||
=*/
|
||||
void
|
||||
optionSaveState(tOptions* pOpts)
|
||||
optionSaveState(tOptions * pOpts)
|
||||
{
|
||||
tOptions* p = (tOptions*)pOpts->pSavedState;
|
||||
tOptions * p = (tOptions*)pOpts->pSavedState;
|
||||
|
||||
if (p == NULL) {
|
||||
size_t sz = sizeof(*pOpts) + (pOpts->optCt * sizeof(tOptDesc));
|
||||
size_t sz = sizeof(*pOpts)
|
||||
+ ((size_t)pOpts->optCt * sizeof(tOptDesc));
|
||||
p = AGALOC(sz, "saved option state");
|
||||
if (p == NULL) {
|
||||
tCC* pzName = pOpts->pzProgName;
|
||||
if (pzName == NULL) {
|
||||
pzName = pOpts->pzPROGNAME;
|
||||
if (pzName == NULL)
|
||||
pzName = zNil;
|
||||
}
|
||||
fprintf(stderr, zCantSave, pzName, sz);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pOpts->pSavedState = p;
|
||||
}
|
||||
|
||||
memcpy(p, pOpts, sizeof(*p));
|
||||
memcpy(p + 1, pOpts->pOptDesc, p->optCt * sizeof(tOptDesc));
|
||||
memcpy(p + 1, pOpts->pOptDesc, (size_t)p->optCt * sizeof(tOptDesc));
|
||||
|
||||
fixupSavedOptionArgs(pOpts);
|
||||
}
|
||||
@@ -141,7 +134,7 @@ optionRestore(tOptions* pOpts)
|
||||
tOptions* p = (tOptions*)pOpts->pSavedState;
|
||||
|
||||
if (p == NULL) {
|
||||
tCC* pzName = pOpts->pzProgName;
|
||||
char const * pzName = pOpts->pzProgName;
|
||||
if (pzName == NULL) {
|
||||
pzName = pOpts->pzPROGNAME;
|
||||
if (pzName == NULL)
|
||||
@@ -155,7 +148,7 @@ optionRestore(tOptions* pOpts)
|
||||
optionFree(pOpts);
|
||||
|
||||
memcpy(pOpts, p, sizeof(*p));
|
||||
memcpy(pOpts->pOptDesc, p+1, p->optCt * sizeof(tOptDesc));
|
||||
memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc));
|
||||
pOpts->pSavedState = p;
|
||||
|
||||
fixupSavedOptionArgs(pOpts);
|
||||
@@ -213,13 +206,15 @@ optionFree(tOptions* pOpts)
|
||||
if (pOpts->pSavedState != NULL) {
|
||||
tOptions * p = (tOptions*)pOpts->pSavedState;
|
||||
memcpy(pOpts, p, sizeof(*p));
|
||||
memcpy(pOpts->pOptDesc, p+1, p->optCt * sizeof(tOptDesc));
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user