mirror of
https://github.com/nmap/nmap.git
synced 2025-12-17 05:09:00 +00:00
Fixed indentation & style.
indent -nut -i2 -kr -br -brs -brf -l0 -bad -npcs -nprs -ncs nbase_str.c + manual adjustements.
This commit is contained in:
@@ -100,69 +100,76 @@
|
|||||||
|
|
||||||
#ifndef HAVE_STRCASESTR
|
#ifndef HAVE_STRCASESTR
|
||||||
char *strcasestr(const char *haystack, const char *pneedle) {
|
char *strcasestr(const char *haystack, const char *pneedle) {
|
||||||
char buf[512];
|
char buf[512];
|
||||||
unsigned int needlelen;
|
unsigned int needlelen;
|
||||||
const char *p;
|
const char *p;
|
||||||
char *needle, *q, *foundto;
|
char *needle, *q, *foundto;
|
||||||
|
|
||||||
/* Should crash if !pneedle -- this is OK */
|
/* Should crash if !pneedle -- this is OK */
|
||||||
if (!*pneedle) return (char *) haystack;
|
if (!*pneedle)
|
||||||
if (!haystack) return NULL;
|
return (char *)haystack;
|
||||||
|
if (!haystack)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
needlelen = (unsigned int) strlen(pneedle);
|
needlelen = (unsigned int)strlen(pneedle);
|
||||||
if (needlelen >= sizeof(buf)) {
|
if (needlelen >= sizeof(buf))
|
||||||
needle = (char *) safe_malloc(needlelen + 1);
|
needle = (char *)safe_malloc(needlelen + 1);
|
||||||
} else needle = buf;
|
else
|
||||||
p = pneedle; q = needle;
|
needle = buf;
|
||||||
while((*q++ = tolower((int) (unsigned char) *p++)))
|
|
||||||
;
|
p = pneedle;
|
||||||
p = haystack - 1; foundto = needle;
|
q = needle;
|
||||||
while(*++p) {
|
|
||||||
if(tolower((int) (unsigned char) *p) == *foundto) {
|
while ((*q++ = tolower((int)(unsigned char)*p++)))
|
||||||
if(!*++foundto) {
|
;
|
||||||
/* Yeah, we found it */
|
|
||||||
if (needlelen >= sizeof(buf))
|
p = haystack - 1;
|
||||||
free(needle);
|
foundto = needle;
|
||||||
return (char *) (p - needlelen + 1);
|
while (*++p) {
|
||||||
}
|
if (tolower((int)(unsigned char)*p) == *foundto) {
|
||||||
} else foundto = needle;
|
if (!*++foundto) {
|
||||||
}
|
/* Yeah, we found it */
|
||||||
if (needlelen >= sizeof(buf))
|
if (needlelen >= sizeof(buf))
|
||||||
free(needle);
|
free(needle);
|
||||||
return NULL;
|
return (char *)(p - needlelen + 1);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
foundto = needle;
|
||||||
|
}
|
||||||
|
if (needlelen >= sizeof(buf))
|
||||||
|
free(needle);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int Strncpy(char *dest, const char *src, size_t n) {
|
int Strncpy(char *dest, const char *src, size_t n) {
|
||||||
strncpy(dest, src, n);
|
strncpy(dest, src, n);
|
||||||
if (dest[n-1] == '\0')
|
if (dest[n - 1] == '\0')
|
||||||
return 0;
|
return 0;
|
||||||
dest[n-1] = '\0';
|
dest[n - 1] = '\0';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vsnprintf(char *s, size_t n, const char *fmt, va_list ap)
|
int Vsnprintf(char *s, size_t n, const char *fmt, va_list ap) {
|
||||||
{
|
int ret;
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = vsnprintf(s, n, fmt, ap);
|
ret = vsnprintf(s, n, fmt, ap);
|
||||||
|
|
||||||
if (ret < 0 || (unsigned) ret >= n)
|
if (ret < 0 || (unsigned)ret >= n)
|
||||||
s[n - 1] = '\0';
|
s[n - 1] = '\0';
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Snprintf(char *s, size_t n, const char *fmt, ...)
|
int Snprintf(char *s, size_t n, const char *fmt, ...) {
|
||||||
{
|
va_list ap;
|
||||||
va_list ap;
|
int ret;
|
||||||
int ret;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = Vsnprintf(s, n, fmt, ap);
|
ret = Vsnprintf(s, n, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a new allocated null-terminated string from the bytes [start, end). */
|
/* Make a new allocated null-terminated string from the bytes [start, end). */
|
||||||
@@ -170,7 +177,7 @@ char *mkstr(const char *start, const char *end) {
|
|||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
assert(end >= start);
|
assert(end >= start);
|
||||||
s = (char *) safe_malloc(end - start + 1);
|
s = (char *)safe_malloc(end - start + 1);
|
||||||
memcpy(s, start, end - start);
|
memcpy(s, start, end - start);
|
||||||
s[end - start] = '\0';
|
s[end - start] = '\0';
|
||||||
|
|
||||||
@@ -188,7 +195,7 @@ int alloc_vsprintf(char **strp, const char *fmt, va_list va) {
|
|||||||
s = NULL;
|
s = NULL;
|
||||||
size = 32;
|
size = 32;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
s = (char *) safe_realloc(s, size);
|
s = (char *)safe_realloc(s, size);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
va_tmp = va;
|
va_tmp = va;
|
||||||
@@ -213,8 +220,9 @@ int alloc_vsprintf(char **strp, const char *fmt, va_list va) {
|
|||||||
printable (as defined by isprint()) */
|
printable (as defined by isprint()) */
|
||||||
int stringisprintable(const char *str, int strlength) {
|
int stringisprintable(const char *str, int strlength) {
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i < strlength; i++)
|
|
||||||
if (!isprint((int) (unsigned char) str[i]))
|
for (i = 0; i < strlength; i++)
|
||||||
|
if (!isprint((int)(unsigned char)str[i]))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -223,8 +231,9 @@ int stringisprintable(const char *str, int strlength) {
|
|||||||
/* Convert non-printable characters to replchar in the string */
|
/* Convert non-printable characters to replchar in the string */
|
||||||
void replacenonprintable(char *str, int strlength, char replchar) {
|
void replacenonprintable(char *str, int strlength, char replchar) {
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i < strlength; i++)
|
|
||||||
if (!isprint((int) (unsigned char) str[i]))
|
for (i = 0; i < strlength; i++)
|
||||||
|
if (!isprint((int)(unsigned char)str[i]))
|
||||||
str[i] = replchar;
|
str[i] = replchar;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -264,7 +273,7 @@ char *path_get_dirname(const char *path) {
|
|||||||
if (i == 0)
|
if (i == 0)
|
||||||
return strdup("/");
|
return strdup("/");
|
||||||
|
|
||||||
result = (char *) safe_malloc(i + 1);
|
result = (char *)safe_malloc(i + 1);
|
||||||
strncpy(result, path, i);
|
strncpy(result, path, i);
|
||||||
result[i] = '\0';
|
result[i] = '\0';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user