From cc4b04cf84c3d7526ac3e334c7fa4a4b6539537b Mon Sep 17 00:00:00 2001 From: Nickolai Zeldovich Date: Mon, 10 Mar 2003 23:29:53 +0000 Subject: [PATCH] STABLE12-add-useful-string-functions-20020822 Add two useful functions for string operations: afs_strdup() and afs_osi_FreeStr(). Will be used by an upcoming patch. (cherry picked from commit 5d36376c07c665b175440e51b03fd85fc58422b0) --- src/afs/UKERNEL/afs_usrops.c | 5 +++++ src/afs/afs_callback.c | 12 +++++++++--- src/afs/afs_osi.c | 4 ++++ src/afs/afs_prototypes.h | 1 + src/afs/afs_util.c | 29 +++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/afs/UKERNEL/afs_usrops.c b/src/afs/UKERNEL/afs_usrops.c index 11a55aa7b5..9648b973cf 100644 --- a/src/afs/UKERNEL/afs_usrops.c +++ b/src/afs/UKERNEL/afs_usrops.c @@ -932,6 +932,11 @@ void afs_osi_Free(void *ptr, size_t size) free(ptr); } +void afs_osi_FreeStr(char *ptr) +{ + free(ptr); +} + void *osi_AllocLargeSpace(size_t size) { AFS_STATCNT(osi_AllocLargeSpace); diff --git a/src/afs/afs_callback.c b/src/afs/afs_callback.c index 55639ea606..88219f282c 100644 --- a/src/afs/afs_callback.c +++ b/src/afs/afs_callback.c @@ -1386,7 +1386,9 @@ int SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum, afs_int32 i, sn; struct cell *tcell; - RX_AFS_GLOCK(); +#ifdef RX_ENABLE_LOCKS + AFS_GLOCK(); +#endif /* RX_ENABLE_LOCKS */ AFS_STATCNT(SRXAFSCB_GetCellByNum); a_hosts->serverList_val = 0; @@ -1395,7 +1397,9 @@ int SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum, tcell = afs_GetCellStale(a_cellnum, READ_LOCK); if (!tcell) { *a_name = afs_strdup(""); - RX_AFS_GUNLOCK(); +#ifdef RX_ENABLE_LOCKS + AFS_GUNLOCK(); +#endif /* RX_ENABLE_LOCKS */ return 0; } @@ -1412,7 +1416,9 @@ int SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum, ReleaseReadLock(&tcell->lock); afs_PutCell(tcell, READ_LOCK); - RX_AFS_GUNLOCK(); +#ifdef RX_ENABLE_LOCKS + AFS_GUNLOCK(); +#endif /* RX_ENABLE_LOCKS */ return 0; } diff --git a/src/afs/afs_osi.c b/src/afs/afs_osi.c index b048ec382d..cea0d04c71 100644 --- a/src/afs/afs_osi.c +++ b/src/afs/afs_osi.c @@ -494,6 +494,10 @@ void afs_osi_Free(void *x, size_t asize) #endif } +void afs_osi_FreeStr(char *x) +{ + afs_osi_Free(x, strlen(x) + 1); +} /* ? is it moderately likely that there are dirty VM pages associated with * this vnode? diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index 52162ece77..a100623252 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -110,6 +110,7 @@ extern void afs_GCPAGs_perproc_func(AFS_PROC *pproc); extern char *afs_cv2string(char *ttp, afs_uint32 aval); extern int afs_strcasecmp(char *s1, char *s2); extern char *afs_strchr(char *s, int c); +extern char *afs_strdup(char *s); extern void print_internet_address(char *preamble, struct srvAddr *sa, char *postamble, int flag); extern afs_int32 afs_data_pointer_to_int32(const void *p); diff --git a/src/afs/afs_util.c b/src/afs/afs_util.c index e761460726..d33bf199e4 100644 --- a/src/afs/afs_util.c +++ b/src/afs/afs_util.c @@ -81,6 +81,35 @@ char *afs_strchr(char *s, int c) return NULL; } +int afs_strcasecmp(char *s1, char *s2) +{ + while (*s1 && *s2) { + char c1, c2; + + c1 = *s1++; + c2 = *s2++; + if (c1 >= 'A' && c1 <= 'Z') c1 += 0x20; + if (c2 >= 'A' && c2 <= 'Z') c2 += 0x20; + if (c1 != c2) + return c1-c2; + } + + return *s1 - *s2; +} + +char *afs_strdup(char *s) +{ + char *n; + int cc; + + cc = strlen(s) + 1; + n = (char *) afs_osi_Alloc(cc); + if (n) + memcpy(n, s, cc); + + return n; +} + void print_internet_address(char *preamble, struct srvAddr *sa, char *postamble, int flag) {