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 5d36376c07)
This commit is contained in:
Nickolai Zeldovich 2003-03-10 23:29:53 +00:00 committed by Derrick Brashear
parent cdb8a859c4
commit cc4b04cf84
5 changed files with 48 additions and 3 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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?

View File

@ -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);

View File

@ -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)
{