Exemple #1
0
/** set_error_details
  *
  *     Generates error details in the dropt context.
  *
  * PARAMETERS:
  *     IN/OUT context    : The dropt context.
  *                         Must not be NULL.
  *     IN err            : The error code.
  *     IN optionName     : The name of the option we failed on.
  *                         optionName.s must not be NULL.
  *     IN optionArgument : The value of the option we failed on.
  *                         Pass NULL if unwanted.
  */
static void
set_error_details(dropt_context * context, dropt_error err,
                  char_array optionName,
                  const dropt_char * optionArgument)
{
  assert(context != NULL);
  assert(optionName.s != NULL);

  context->errorDetails.err = err;

  free(context->errorDetails.optionName);
  free(context->errorDetails.optionArgument);

  context->errorDetails.optionName = dropt_strndup(optionName.s, optionName.len);
  context->errorDetails.optionArgument = (optionArgument == NULL)
                                         ? NULL
                                         : dropt_strdup(optionArgument);

  /* The message will be generated lazily on retrieval. */
  free(context->errorDetails.message);
  context->errorDetails.message = NULL;
}
Exemple #2
0
/** dropt_strdup
  *
  *     Duplicates a string.
  *
  * PARAMETERS:
  *     IN s : A NUL-terminated string to duplicate.
  *
  * RETURNS:
  *     The duplicated string.  The caller is responsible for calling
  *       free() on it when no longer needed.
  *     Returns NULL on error.
  */
dropt_char*
dropt_strdup(const dropt_char* s)
{
    return dropt_strndup(s, SIZE_MAX);
}