Skip to content

Commit

Permalink
Update cupsAdd/GetIntegerOption to use long type.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Oct 22, 2023
1 parent df0968e commit 1f186c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ libcups v3.0rc1 (TBD)
---------------------

- Updated list of attributes included in the destination options.
- Updated `cupsAddIntegerOption` and `cupsGetIntegerOption` to use the `long`
type.


libcups v3.0b2 (October 5, 2023)
Expand Down
4 changes: 2 additions & 2 deletions cups/cups.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ typedef const char *(*cups_password_cb_t)(const char *prompt, http_t *http, cons

extern size_t cupsAddDest(const char *name, const char *instance, size_t num_dests, cups_dest_t **dests) _CUPS_PUBLIC;
extern size_t cupsAddDestMediaOptions(http_t *http, cups_dest_t *dest, cups_dinfo_t *dinfo, unsigned flags, cups_media_t *media, size_t num_options, cups_option_t **options) _CUPS_PUBLIC;
extern size_t cupsAddIntegerOption(const char *name, int value, size_t num_options, cups_option_t **options) _CUPS_PUBLIC;
extern size_t cupsAddIntegerOption(const char *name, long value, size_t num_options, cups_option_t **options) _CUPS_PUBLIC;
extern size_t cupsAddOption(const char *name, const char *value, size_t num_options, cups_option_t **options) _CUPS_PUBLIC;
extern bool cupsAreCredentialsValidForName(const char *common_name, const char *credentials);

Expand Down Expand Up @@ -357,7 +357,7 @@ extern ipp_status_t cupsGetError(void) _CUPS_PUBLIC;
extern const char *cupsGetErrorString(void) _CUPS_PUBLIC;
extern http_status_t cupsGetFd(http_t *http, const char *resource, int fd) _CUPS_PUBLIC;
extern http_status_t cupsGetFile(http_t *http, const char *resource, const char *filename) _CUPS_PUBLIC;
extern int cupsGetIntegerOption(const char *name, size_t num_options, cups_option_t *options) _CUPS_PUBLIC;
extern long cupsGetIntegerOption(const char *name, size_t num_options, cups_option_t *options) _CUPS_PUBLIC;
extern size_t cupsGetJobs(http_t *http, cups_job_t **jobs, const char *name, bool myjobs, cups_whichjobs_t whichjobs) _CUPS_PUBLIC;
extern cups_dest_t *cupsGetNamedDest(http_t *http, const char *name, const char *instance) _CUPS_PUBLIC;
extern const char *cupsGetOption(const char *name, size_t num_options, cups_option_t *options) _CUPS_PUBLIC;
Expand Down
23 changes: 12 additions & 11 deletions cups/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ static size_t cups_find_option(const char *name, size_t num_options, cups_option
size_t // O - Number of options
cupsAddIntegerOption(
const char *name, // I - Name of option
int value, // I - Value of option
long value, // I - Value of option
size_t num_options, // I - Number of options
cups_option_t **options) // IO - Pointer to options
{
char strvalue[32]; // String value


snprintf(strvalue, sizeof(strvalue), "%d", value);
snprintf(strvalue, sizeof(strvalue), "%ld", value);

return (cupsAddOption(name, strvalue, num_options, options));
}
Expand Down Expand Up @@ -139,11 +139,11 @@ cupsFreeOptions(
//
// 'cupsGetIntegerOption()' - Get an integer option value.
//
// INT_MIN is returned when the option does not exist, is not an integer, or
// exceeds the range of values for the "int" type.
// `LONG_MIN` is returned when the option does not exist, is not an integer, or
// exceeds the range of values for the `long` type.
//

int // O - Option value or `INT_MIN`
long // O - Option value or `LONG_MIN`
cupsGetIntegerOption(
const char *name, // I - Name of option
size_t num_options, // I - Number of options
Expand All @@ -152,17 +152,18 @@ cupsGetIntegerOption(
const char *value = cupsGetOption(name, num_options, options);
// String value of option
char *ptr; // Pointer into string value
long intvalue; // Integer value
long lvalue; // Integer value


if (!value || !*value)
return (INT_MIN);
return (LONG_MIN);

intvalue = strtol(value, &ptr, 10);
if (intvalue < INT_MIN || intvalue > INT_MAX || *ptr)
return (INT_MIN);
lvalue = strtol(value, &ptr, 10);

return ((int)intvalue);
if (*ptr)
return (LONG_MIN);
else
return (lvalue);
}


Expand Down

0 comments on commit 1f186c1

Please sign in to comment.