X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=include%2Flibiberty.h;h=141cb886a85000f86080342f90ea6c44c8720bb3;hb=43327b208ec6452c1a6accd40be965cdfa5c86a3;hp=bcc1f9afaf7b731f486b752f0f42578e44455223;hpb=b55f967878a4f7905f78b05a9c37457797b1c7ed;p=deliverable%2Fbinutils-gdb.git diff --git a/include/libiberty.h b/include/libiberty.h index bcc1f9afaf..141cb886a8 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -1,7 +1,6 @@ /* Function declarations for libiberty. - Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010, 2011, 2013 Free Software Foundation, Inc. + Copyright (C) 1997-2020 Free Software Foundation, Inc. Note - certain prototypes declared in this header file are for functions whoes implementation copyright does not belong to the @@ -81,7 +80,7 @@ extern void freeargv (char **); /* Duplicate an argument vector. Allocates memory using malloc. Use freeargv to free the vector. */ -extern char **dupargv (char **) ATTRIBUTE_MALLOC; +extern char **dupargv (char * const *) ATTRIBUTE_MALLOC; /* Expand "@file" arguments in argv. */ @@ -89,11 +88,11 @@ extern void expandargv (int *, char ***); /* Write argv to an @-file, inserting necessary quoting. */ -extern int writeargv (char **, FILE *); +extern int writeargv (char * const *, FILE *); /* Return the number of elements in argv. */ -extern int countargv (char**); +extern int countargv (char * const *); /* Return the last component of a path name. Note that we can't use a prototype here because the parameter is declared inconsistently @@ -138,6 +137,10 @@ extern const char *unix_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRI extern char *lrealpath (const char *); +/* Return true when FD file descriptor exists. */ + +extern int is_valid_fd (int fd); + /* Concatenate an arbitrary number of strings. You must pass NULL as the last argument of this function, to terminate the list of strings. Allocates memory using xmalloc. */ @@ -227,6 +230,11 @@ extern char *make_relative_prefix (const char *, const char *, extern char *make_relative_prefix_ignore_links (const char *, const char *, const char *) ATTRIBUTE_MALLOC; +/* Returns a pointer to a directory path suitable for creating temporary + files in. */ + +extern const char *choose_tmpdir (void) ATTRIBUTE_RETURNS_NONNULL; + /* Choose a temporary directory to use for scratch files. */ extern char *choose_temp_base (void) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; @@ -235,6 +243,11 @@ extern char *choose_temp_base (void) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; extern char *make_temp_file (const char *) ATTRIBUTE_MALLOC; +/* Return a temporary file name with given PREFIX and SUFFIX + or NULL if unable to create one. */ + +extern char *make_temp_file_with_prefix (const char *, const char *) ATTRIBUTE_MALLOC; + /* Remove a link to a file unless it is special. */ extern int unlink_if_ordinary (const char *); @@ -301,30 +314,30 @@ extern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN; message to stderr (using the name set by xmalloc_set_program_name, if any) and then call xexit. */ -extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; +extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1 ATTRIBUTE_WARN_UNUSED_RESULT; /* Reallocate memory without fail. This works like xmalloc. Note, realloc type functions are not suitable for attribute malloc since they may return the same address across multiple calls. */ -extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL; +extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_2 ATTRIBUTE_WARN_UNUSED_RESULT; /* Allocate memory without fail and set it to zero. This works like xmalloc. */ -extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; +extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1_2 ATTRIBUTE_WARN_UNUSED_RESULT; /* Copy a string into a memory buffer without fail. */ -extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; +extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT; /* Copy at most N characters from string into a buffer without fail. */ -extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; +extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT; /* Copy an existing memory buffer to a new memory buffer without fail. */ -extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; +extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT; /* Physical memory routines. Return values are in BYTES. */ extern double physmem_total (void); @@ -393,6 +406,17 @@ extern void hex_init (void); /* Save files used for communication between processes. */ #define PEX_SAVE_TEMPS 0x4 +/* Max number of alloca bytes per call before we must switch to malloc. + + ?? Swiped from gnulib's regex_internal.h header. Is this actually + the case? This number seems arbitrary, though sane. + + The OS usually guarantees only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + allocate anything larger than 4096 bytes. Also care for the possibility + of a few compiler-allocated temporary stack slots. */ +#define MAX_ALLOCA_SIZE 4032 + /* Prepare to execute one or more programs, with standard output of each program fed to standard input of the next. FLAGS As above. @@ -538,7 +562,7 @@ extern FILE *pex_input_file (struct pex_obj *obj, int flags, extern FILE *pex_input_pipe (struct pex_obj *obj, int binary); /* Read the standard output of the last program to be executed. - pex_run can not be called after this. BINARY should be non-zero if + pex_run cannot be called after this. BINARY should be non-zero if the file should be opened in binary mode; this is ignored on Unix. Returns NULL on error. Don't call fclose on the returned FILE; it will be closed by pex_free. */ @@ -546,7 +570,7 @@ extern FILE *pex_input_pipe (struct pex_obj *obj, int binary); extern FILE *pex_read_output (struct pex_obj *, int binary); /* Read the standard error of the last program to be executed. - pex_run can not be called after this. BINARY should be non-zero if + pex_run cannot be called after this. BINARY should be non-zero if the file should be opened in binary mode; this is ignored on Unix. Returns NULL on error. Don't call fclose on the returned FILE; it will be closed by pex_free. */ @@ -617,20 +641,30 @@ extern int pexecute (const char *, char * const *, const char *, extern int pwait (int, int *, int); -#if !HAVE_DECL_ASPRINTF +#if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF /* Like sprintf but provides a pointer to malloc'd storage, which must be freed by the caller. */ extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; #endif -#if !HAVE_DECL_VASPRINTF +/* Like asprintf but allocates memory without fail. This works like + xmalloc. */ + +extern char *xasprintf (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_PRINTF_1; + +#if defined(HAVE_DECL_VASPRINTF) && !HAVE_DECL_VASPRINTF /* Like vsprintf but provides a pointer to malloc'd storage, which must be freed by the caller. */ extern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0); #endif +/* Like vasprintf but allocates memory without fail. This works like + xmalloc. */ + +extern char *xvasprintf (const char *, va_list) ATTRIBUTE_MALLOC ATTRIBUTE_PRINTF(1,0); + #if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF /* Like sprintf but prints at most N characters. */ extern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3; @@ -650,6 +684,33 @@ extern size_t strnlen (const char *, size_t); extern int strverscmp (const char *, const char *); #endif +#if defined(HAVE_DECL_STRTOL) && !HAVE_DECL_STRTOL +extern long int strtol (const char *nptr, + char **endptr, int base); +#endif + +#if defined(HAVE_DECL_STRTOUL) && !HAVE_DECL_STRTOUL +extern unsigned long int strtoul (const char *nptr, + char **endptr, int base); +#endif + +#if defined(HAVE_LONG_LONG) && defined(HAVE_DECL_STRTOLL) && !HAVE_DECL_STRTOLL +__extension__ +extern long long int strtoll (const char *nptr, + char **endptr, int base); +#endif + +#if defined(HAVE_LONG_LONG) && defined(HAVE_DECL_STRTOULL) && !HAVE_DECL_STRTOULL +__extension__ +extern unsigned long long int strtoull (const char *nptr, + char **endptr, int base); +#endif + +#if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP +/* Compare version strings. */ +extern int strverscmp (const char *, const char *); +#endif + /* Set the title of a process */ extern void setproctitle (const char *name, ...); @@ -672,7 +733,7 @@ extern void *C_alloca (size_t) ATTRIBUTE_MALLOC; # define ASTRDUP(X) \ (__extension__ ({ const char *const libiberty_optr = (X); \ const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ - char *const libiberty_nptr = (char *const) alloca (libiberty_len); \ + char *const libiberty_nptr = (char *) alloca (libiberty_len); \ (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) #else # define alloca(x) C_alloca(x)