From bba76f2085975aeba776356b2556c99b8c882bd5 Mon Sep 17 00:00:00 2001 From: kbyanc Date: Tue, 18 Dec 2001 00:48:44 +0000 Subject: Const'ify the CDB format string passed to the CDB parsing routines (csio_decode_visit() and family). Reviewed by: ken --- lib/libcam/scsi_cmdparse.c | 66 ++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 25 deletions(-) (limited to 'lib/libcam/scsi_cmdparse.c') diff --git a/lib/libcam/scsi_cmdparse.c b/lib/libcam/scsi_cmdparse.c index e853f2d..f0cb724 100644 --- a/lib/libcam/scsi_cmdparse.c +++ b/lib/libcam/scsi_cmdparse.c @@ -100,7 +100,7 @@ __FBSDID("$FreeBSD$"); static int do_buff_decode(u_int8_t *databuf, size_t len, void (*arg_put)(void *, int , void *, int, char *), - void *puthook, char *fmt, va_list ap) + void *puthook, const char *fmt, va_list ap) { int assigned = 0; int width; @@ -111,6 +111,7 @@ do_buff_decode(u_int8_t *databuf, size_t len, 0x1f, 0x3f, 0x7f, 0xff}; int value; u_char *base = databuf; + char *intendp; char letter; char field_name[80]; @@ -178,7 +179,8 @@ do_buff_decode(u_int8_t *databuf, size_t len, case 't': /* Bit (field) */ case 'b': /* Bits */ fmt++; - width = strtol(fmt, &fmt, 10); + width = strtol(fmt, &intendp, 10); + fmt = intendp; if (width > 8) done = 1; else { @@ -203,7 +205,8 @@ do_buff_decode(u_int8_t *databuf, size_t len, case 'i': /* Integral values */ shift = 0; fmt++; - width = strtol(fmt, &fmt, 10); + width = strtol(fmt, &intendp, 10); + fmt = intendp; switch(width) { case 1: ARG_PUT(*databuf); @@ -241,7 +244,8 @@ do_buff_decode(u_int8_t *databuf, size_t len, spaces */ shift = 0; fmt++; - width = strtol(fmt, &fmt, 10); + width = strtol(fmt, &intendp, 10); + fmt = intendp; if (!suppress) { if (arg_put) (*arg_put)(puthook, @@ -283,8 +287,10 @@ do_buff_decode(u_int8_t *databuf, size_t len, */ width = (arg_put) ? 0 : va_arg(ap, int); fmt++; - } else - width = strtol(fmt, &fmt, 10); + } else { + width = strtol(fmt, &intendp, 10); + fmt = intendp; + } if (plus) databuf += width; /* Relative seek */ @@ -341,10 +347,11 @@ do_buff_decode(u_int8_t *databuf, size_t len, */ static int -next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, +next_field(const char **pp, char *fmt, int *width_p, int *value_p, char *name, int n_name, int *error_p, int *suppress_p) { - char *p = *pp; + const char *p = *pp; + char *intendp; int something = 0; @@ -404,7 +411,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, suppress = 1; } else if (isxdigit(*p)) { something = 1; - value = strtol(p, &p, 16); + value = strtol(p, &intendp, 16); + p = intendp; state = START_FIELD; } else if (tolower(*p) == 'v') { p++; @@ -421,7 +429,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, *fmt = 'i'; field_size = 8; - field_width = strtol(p, &p, 10); + field_width = strtol(p, &intendp, 10); + p = intendp; state = DONE; } else if (tolower(*p) == 't') { @@ -436,7 +445,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, *fmt = 'b'; field_size = 1; - field_width = strtol(p, &p, 10); + field_width = strtol(p, &intendp, 10); + p = intendp; state = DONE; } else if (tolower(*p) == 's') { /* Seek */ @@ -448,7 +458,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, value = *value_p; } else { something = 1; - value = strtol(p, &p, 0); + value = strtol(p, &intendp, 0); + p = intendp; } state = DONE; } else { @@ -473,7 +484,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, if (isdigit(*p)) { *fmt = 'b'; field_size = 1; - field_width = strtol(p, &p, 10); + field_width = strtol(p, &intendp, 10); + p = intendp; state = DONE; } else if (*p == 'i') { @@ -482,7 +494,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, *fmt = 'i'; field_size = 8; - field_width = strtol(p, &p, 10); + field_width = strtol(p, &intendp, 10); + p = intendp; state = DONE; } else if (*p == 'b') { @@ -491,7 +504,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, *fmt = 'b'; field_size = 1; - field_width = strtol(p, &p, 10); + field_width = strtol(p, &intendp, 10); + p = intendp; state = DONE; } else { fprintf(stderr, "Invalid startfield %c " @@ -522,7 +536,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, static int do_encode(u_char *buff, size_t vec_max, size_t *used, - int (*arg_get)(void *, char *), void *gethook, char *fmt, va_list ap) + int (*arg_get)(void *, char *), void *gethook, const char *fmt, + va_list ap) { int ind; int shift; @@ -642,7 +657,7 @@ do_encode(u_char *buff, size_t vec_max, size_t *used, } int -csio_decode(struct ccb_scsiio *csio, char *fmt, ...) +csio_decode(struct ccb_scsiio *csio, const char *fmt, ...) { va_list ap; @@ -653,7 +668,7 @@ csio_decode(struct ccb_scsiio *csio, char *fmt, ...) } int -csio_decode_visit(struct ccb_scsiio *csio, char *fmt, +csio_decode_visit(struct ccb_scsiio *csio, const char *fmt, void (*arg_put)(void *, int, void *, int, char *), void *puthook) { @@ -673,7 +688,7 @@ csio_decode_visit(struct ccb_scsiio *csio, char *fmt, } int -buff_decode(u_int8_t *buff, size_t len, char *fmt, ...) +buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...) { va_list ap; @@ -683,7 +698,7 @@ buff_decode(u_int8_t *buff, size_t len, char *fmt, ...) } int -buff_decode_visit(u_int8_t *buff, size_t len, char *fmt, +buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt, void (*arg_put)(void *, int, void *, int, char *), void *puthook) { @@ -707,7 +722,8 @@ buff_decode_visit(u_int8_t *buff, size_t len, char *fmt, */ int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, u_int32_t dxfer_len, - u_int32_t flags, int retry_count, int timeout, char *cmd_spec, ...) + u_int32_t flags, int retry_count, int timeout, const char *cmd_spec, + ...) { size_t cmdlen; int retval; @@ -741,7 +757,7 @@ csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, u_int32_t dxfer_len, int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, u_int32_t dxfer_len, u_int32_t flags, int retry_count, - int timeout, char *cmd_spec, + int timeout, const char *cmd_spec, int (*arg_get)(void *hook, char *field_name), void *gethook) { va_list ap; @@ -781,7 +797,7 @@ csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, } int -csio_encode(struct ccb_scsiio *csio, char *fmt, ...) +csio_encode(struct ccb_scsiio *csio, const char *fmt, ...) { va_list ap; @@ -794,7 +810,7 @@ csio_encode(struct ccb_scsiio *csio, char *fmt, ...) } int -buff_encode_visit(u_int8_t *buff, size_t len, char *fmt, +buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt, int (*arg_get)(void *hook, char *field_name), void *gethook) { va_list ap; @@ -812,7 +828,7 @@ buff_encode_visit(u_int8_t *buff, size_t len, char *fmt, } int -csio_encode_visit(struct ccb_scsiio *csio, char *fmt, +csio_encode_visit(struct ccb_scsiio *csio, const char *fmt, int (*arg_get)(void *hook, char *field_name), void *gethook) { va_list ap; -- cgit v1.1