NCBI C++ ToolKit
Functions | Variables
ncbi_ansi_ext.c File Reference
#include "ncbi_ansi_ext.h"
#include "ncbi_assert.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+ Include dependency graph for ncbi_ansi_ext.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Functions

size_t NCBI_strnlen (const char *str, size_t maxlen)
 Return the number of characters in the string pointed to by "str" (not including the terminating '\0' character) but no more than "maxlen" (if the '\0' character hasn't been found within the first "maxlen" characters). More...
 
char * NCBI_strdup (const char *str)
 Create a copy of string "str". More...
 
char * NCBI_strndup (const char *str, size_t n)
 Create a copy of up to "n" first characters of string "str". More...
 
int NCBI_strcasecmp (const char *s1, const char *s2)
 Compare "s1" and "s2", ignoring case. More...
 
int NCBI_strncasecmp (const char *s1, const char *s2, size_t n)
 Compare no more than "n" characters of "s1" and "s2", ignoring case. More...
 
char * NCBI_strupr (char *s)
 Convert a string to all uppercase, then return pointer to the altered string. More...
 
char * NCBI_strlwr (char *s)
 Convert a string to all lowercase, then return pointer to the altered string. More...
 
char * strncpy0 (char *s1, const char *s2, size_t n)
 Copy not more than "n" characters from string "s2" into "s1", and return the result, which is always '\0'-terminated. More...
 
void * NCBI_memcchr (const void *s, int c, size_t n)
 Find the address of the first occurrence of a byte that is NOT char "c" within the "n" bytes of memory at the address "s". More...
 
void * NCBI_memrchr (const void *s, int c, size_t n)
 Find the address of the last occurrence of char "c" within "n" bytes of a memory block of size "n" beginning at the address "s". More...
 
char * NCBI_simple_ftoa (char *s, double f, int p)
 Locale-independent double-to-ASCII conversion of value "f" into a character buffer pointed to by "s", with a specified precision (mantissa digits) "p". More...
 
double NCBI_simple_atof (const char *s, char **t)
 Locale-independent ASCII-to-double conversion of string "s". More...
 
int NCBI_HasSpaces (const char *s, size_t n)
 Return non-zero(true) if a block of memory based at "s" and of size "n" has any space characters (as defined by isspace(c) of <ctype.h>). More...
 

Variables

static const double x_pow10 [] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 }
 

Function Documentation

◆ NCBI_HasSpaces()

int NCBI_HasSpaces ( const char *  s,
size_t  n 
)

Return non-zero(true) if a block of memory based at "s" and of size "n" has any space characters (as defined by isspace(c) of <ctype.h>).

Return zero (false) if no such characters were found. Note that "s" is not considered to be '\0'-terminated; that is, all "n" positions will be checked.

Note
If "n" is 0, then "s" is not getting accessed (and can be anything, including NULL), and the return value is always 0(false).

Definition at line 250 of file ncbi_ansi_ext.c.

References isspace(), and n.

Referenced by ConnNetInfo_CreateInternal(), ConnNetInfo_GetValue(), ConnNetInfo_GetValueInternal(), ConnNetInfo_GetValueService(), ConnNetInfo_ParseURL(), NcbiOpenURL(), s_gethostbyaddr_(), s_gethostname(), s_SocketConnectorBuilder(), x_ServiceName(), x_SetupConnectionParams(), and x_SetupHttpProxy().

◆ NCBI_memcchr()

void* NCBI_memcchr ( const void *  s,
int  c,
size_t  n 
)

Find the address of the first occurrence of a byte that is NOT char "c" within the "n" bytes of memory at the address "s".

Return NULL if all bytes are "c".

Definition at line 145 of file ncbi_ansi_ext.c.

References i, and n.

◆ NCBI_memrchr()

void* NCBI_memrchr ( const void *  s,
int  c,
size_t  n 
)

Find the address of the last occurrence of char "c" within "n" bytes of a memory block of size "n" beginning at the address "s".

HAVE_MEMCCHR

Definition at line 161 of file ncbi_ansi_ext.c.

References i, and n.

◆ NCBI_simple_atof()

double NCBI_simple_atof ( const char *  s,
char **  e 
)

Locale-independent ASCII-to-double conversion of string "s".

Does not work for scientific notation (values including exponent). Sets "e" to point to the character that stopped conversion. Clears "errno" but sets it non-zero in case of conversion errors. Maximal value for the whole part may not exceed the maximal signed long integer, and for mantissa – unsigned long integer. Returns result of the conversion (on error sets errno, returns 0.0).

Note
e == s upon return if no valid input was found and consumed.

Definition at line 196 of file ncbi_ansi_ext.c.

References assert, int, isdigit(), isspace(), n, t, and x_pow10.

Referenced by ConnNetInfo_CreateInternal(), SERV_ReadInfoEx(), and x_Sendmail_InitEnv().

◆ NCBI_simple_ftoa()

char* NCBI_simple_ftoa ( char *  s,
double  f,
int  p 
)

Locale-independent double-to-ASCII conversion of value "f" into a character buffer pointed to by "s", with a specified precision (mantissa digits) "p".

HAVE_MEMRCHR There is an internal limit on precision (so larger values of "p" will be silently truncated). The maximal representable whole part corresponds to the maximal signed long integer. Otherwise, the behavior is undefined. Return the pointer past the output string (points to the terminating '\0').

Definition at line 177 of file ncbi_ansi_ext.c.

References assert, f(), int, and x_pow10.

Referenced by LBSM_SubmitPenaltyOrRerate(), SERV_Print(), and SERV_WriteInfo().

◆ NCBI_strcasecmp()

int NCBI_strcasecmp ( const char *  s1,
const char *  s2 
)

Compare "s1" and "s2", ignoring case.

HAVE_STRNDUP

Definition at line 77 of file ncbi_ansi_ext.c.

References tolower().

◆ NCBI_strdup()

char* NCBI_strdup ( const char *  str)

Create a copy of string "str".

Return an identical malloc()'ed string, which must be explicitly deallocated by free() when no longer needed. Return NULL if the memory allocation failed.

Definition at line 51 of file ncbi_ansi_ext.c.

References malloc(), ncbi::grid::netcache::search::fields::size, and str().

◆ NCBI_strlwr()

char* NCBI_strlwr ( char *  s)

Convert a string to all lowercase, then return pointer to the altered string.

Because the conversion is made in place, the returned pointer is the same as the passed one.

Definition at line 128 of file ncbi_ansi_ext.c.

References t, and tolower().

◆ NCBI_strncasecmp()

int NCBI_strncasecmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Compare no more than "n" characters of "s1" and "s2", ignoring case.

Return less than, equal to or greater than zero if the initial fragment of "s1" is lexicographically less than, equal to or greater than the same fragment of "s2", respectively.

Definition at line 97 of file ncbi_ansi_ext.c.

References n, and tolower().

◆ NCBI_strndup()

char* NCBI_strndup ( const char *  str,
size_t  n 
)

Create a copy of up to "n" first characters of string "str".

HAVE_STRDUP && !NCBI_COMPILER_MSVC

Definition at line 61 of file ncbi_ansi_ext.c.

References malloc(), n, ncbi::grid::netcache::search::fields::size, str(), and strnlen.

◆ NCBI_strnlen()

size_t NCBI_strnlen ( const char *  str,
size_t  maxlen 
)

Return the number of characters in the string pointed to by "str" (not including the terminating '\0' character) but no more than "maxlen" (if the '\0' character hasn't been found within the first "maxlen" characters).

Definition at line 42 of file ncbi_ansi_ext.c.

References str().

◆ NCBI_strupr()

char* NCBI_strupr ( char *  s)

Convert a string to all uppercase, then return pointer to the altered string.

NCBI_COMPILER_MSVC && !HAVE_STRCASECMP

Definition at line 119 of file ncbi_ansi_ext.c.

References t, and toupper().

◆ strncpy0()

char* strncpy0 ( char *  s1,
const char *  s2,
size_t  n 
)

Copy not more than "n" characters from string "s2" into "s1", and return the result, which is always '\0'-terminated.

NOTE: The difference of this function from standard strncpy() is in that the result is _always_ '\0'-terminated and that the function does _not_ pad "s1" with null bytes should "s2" be shorter than "n" characters.

Definition at line 137 of file ncbi_ansi_ext.c.

References n.

Referenced by DBLB_GetServer(), DBLB_GetServerName(), MIME_ComposeContentTypeEx(), NcbiDumpIPRange(), REG_Get(), s_CreateOnTop(), s_DoLog(), s_FTPReply(), s_MakeFrom(), s_REG_Get(), s_SockReadResponse(), SERV_ReadInfoEx(), x_ClientAddress(), x_FTPDir(), x_FTPParseMdtm(), x_FTPParseReply(), x_FTPRetrieveCB(), x_RedirectOK(), x_SetHostPort(), x_strncpy0(), and xx_LoadLocalIPs().

Variable Documentation

◆ x_pow10

const double x_pow10[] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 }
static

HAVE_MEMRCHR

Definition at line 174 of file ncbi_ansi_ext.c.

Referenced by NCBI_simple_atof(), and NCBI_simple_ftoa().

Modified on Fri Feb 23 11:46:58 2024 by modify_doxy.py rev. 669887