1
0
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:
henri
2012-12-20 18:15:59 +00:00
parent f2757be055
commit a90bafc9f4

View File

@@ -100,32 +100,41 @@
#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;
q = needle;
while ((*q++ = tolower((int)(unsigned char)*p++)))
; ;
p = haystack - 1; foundto = needle;
while(*++p) { p = haystack - 1;
if(tolower((int) (unsigned char) *p) == *foundto) { foundto = needle;
if(!*++foundto) { while (*++p) {
if (tolower((int)(unsigned char)*p) == *foundto) {
if (!*++foundto) {
/* Yeah, we found it */ /* Yeah, we found it */
if (needlelen >= sizeof(buf)) if (needlelen >= sizeof(buf))
free(needle); free(needle);
return (char *) (p - needlelen + 1); return (char *)(p - needlelen + 1);
} }
} else foundto = needle; } else
foundto = needle;
} }
if (needlelen >= sizeof(buf)) if (needlelen >= sizeof(buf))
free(needle); free(needle);
@@ -135,26 +144,24 @@ needlelen = (unsigned int) strlen(pneedle);
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;
@@ -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';