sdparm_access.c (sdparm-1.11.tgz) | : | sdparm_access.c (sdparm-1.12.tgz) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright (c) 2005-2020, Douglas Gilbert | * Copyright (c) 2005-2021, Douglas Gilbert | |||
* All rights reserved. | * All rights reserved. | |||
* | * | |||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions are met: | * modification, are permitted provided that the following conditions are met: | |||
* | * | |||
* 1. Redistributions of source code must retain the above copyright notice, | * 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | * this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | |||
* documentation and/or other materials provided with the distribution. | * documentation and/or other materials provided with the distribution. | |||
skipping to change at line 44 | skipping to change at line 44 | |||
#define __STDC_FORMAT_MACROS 1 | #define __STDC_FORMAT_MACROS 1 | |||
#include <inttypes.h> | #include <inttypes.h> | |||
#ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | |||
#include "config.h" | #include "config.h" | |||
#endif | #endif | |||
#include "sdparm.h" | #include "sdparm.h" | |||
#include "sg_lib.h" | #include "sg_lib.h" | |||
#include "sg_unaligned.h" | #include "sg_unaligned.h" | |||
#include "sg_pr2serr.h" | ||||
/* sdparm_access.c : helpers for sdparm to access tables in | /* sdparm_access.c : helpers for sdparm to access tables in | |||
* sdparm_data.c | * sdparm_data.c | |||
*/ | */ | |||
/* Returns true if left argument is "equal" to the right argument. l_pdt_s | ||||
* is a compound PDT (SCSI Peripheral Device Type) or a negative number | ||||
* which represents a wildcard (i.e. match anything). r_pdt_s has a similar | ||||
* form. PDT values are 5 bits long (0 to 31) and a compound pdt_s is | ||||
* formed by shifting the second (upper) PDT by eight bits to the left and | ||||
* OR-ing it with the first PDT. The pdt_s values must be defined so | ||||
* PDT_DISK (0) is _not_ the upper value in a compound pdt_s. */ | ||||
bool | ||||
pdt_s_eq(int l_pdt_s, int r_pdt_s) | ||||
{ | ||||
bool upper_l = !!(l_pdt_s & PDT_UPPER_MASK); | ||||
bool upper_r = !!(r_pdt_s & PDT_UPPER_MASK); | ||||
if ((l_pdt_s < 0) || (r_pdt_s < 0)) | ||||
return true; | ||||
if (!upper_l && !upper_r) | ||||
return l_pdt_s == r_pdt_s; | ||||
else if (upper_l && upper_r) | ||||
return (((PDT_UPPER_MASK & l_pdt_s) == (PDT_UPPER_MASK & r_pdt_s)) || | ||||
((PDT_LOWER_MASK & l_pdt_s) == (PDT_LOWER_MASK & r_pdt_s))); | ||||
else if (upper_l) | ||||
return (((PDT_LOWER_MASK & l_pdt_s) == r_pdt_s) || | ||||
((PDT_UPPER_MASK & l_pdt_s) >> 8) == r_pdt_s); | ||||
return (((PDT_LOWER_MASK & r_pdt_s) == l_pdt_s) || | ||||
((PDT_UPPER_MASK & r_pdt_s) >> 8) == l_pdt_s); | ||||
} | ||||
/* Returns 1 if strings equal (same length, characters same or only differ | /* Returns 1 if strings equal (same length, characters same or only differ | |||
* by case), else returns 0. Assumes 7 bit ASCII (English alphabet). */ | * by case), else returns 0. Assumes 7 bit ASCII (English alphabet). */ | |||
int | int | |||
sdp_strcase_eq(const char * s1p, const char * s2p) | sdp_strcase_eq(const char * s1p, const char * s2p) | |||
{ | { | |||
int c1, c2; | int c1, c2; | |||
do { | do { | |||
c1 = *s1p++; | c1 = *s1p++; | |||
c2 = *s2p++; | c2 = *s2p++; | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 29 lines changed or added |