aboutsummaryrefslogtreecommitdiff
path: root/src/pj_internal.c
diff options
context:
space:
mode:
authorThomas Knudsen <busstoptaktik@users.noreply.github.com>2018-02-07 12:15:04 +0100
committerGitHub <noreply@github.com>2018-02-07 12:15:04 +0100
commit4f00f09f1c306e87dfea3a5bc49dcaae72280e00 (patch)
tree8e1378ed32ac4f9b2badf37fd9b5ceac66d049c8 /src/pj_internal.c
parent4cd6fe1369f52bc53c8e595a218bd0e7426b05db (diff)
downloadPROJ-4f00f09f1c306e87dfea3a5bc49dcaae72280e00.tar.gz
PROJ-4f00f09f1c306e87dfea3a5bc49dcaae72280e00.zip
Shrink PJ_XXX_INFO structs, but keep same syntax. (#775)
* Shrink PJ_XXX_INFO structs, but keep same syntax. A number of the fixed length strings in the INFO structs are simply reflections of material that already exists as static strings at a number of places in the library (or in the case of PJ_INFO, really *should* exist, and now is implemented). This PR replaces these cases of constant length strings with const char pointers. The usage syntax is unchanged, and so is the nice property of having the return value allocated on the stack, and hence not requiring explicit memory management by the caller. proj_info now only does setup once - and the searchpath entry of PJ_INFO is not arbitrarily truncated at 512 bytes. Repeated calls simply returns a copy of already prepared material. The id, description and definition entries of PJ_PROJ_INFO are now also guaranteed to hold the entire text of the corresponding static string, by being represented by a const char pointer to that actual static string. PJ_GRID_INFO and PJ_INIT_INFO (i.e. the two smallest INFO structs) are unchanged. * Eliminate pj_strlcpy - not needed anymore: Remining calls could safely be replaced by strncpy. * Extend PROJ_INFO with paths from pj_set_searchpath. NOTE: Need to call pj_set_searchpath before first call to proj_info Huge thanks to Kristian Evers and Even Rouault for comments, debugging and advice.
Diffstat (limited to 'src/pj_internal.c')
-rw-r--r--src/pj_internal.c54
1 files changed, 3 insertions, 51 deletions
diff --git a/src/pj_internal.c b/src/pj_internal.c
index 6bb33d64..4dbcfbd4 100644
--- a/src/pj_internal.c
+++ b/src/pj_internal.c
@@ -148,56 +148,6 @@ void proj_context_inherit (PJ *parent, PJ *child) {
-/**************************************************************************************/
-size_t pj_strlcpy(char *dst, const char *src, size_t dsize) {
-/***************************************************************************************
- Copy src to string dst of size siz. At most siz-1 characters
- will be copied. Always NUL terminates (unless siz == 0).
- Returns strlen(src); if retval >= siz, truncation occurred.
-
- *
- * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
-
- Source: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/strlcpy.c
-
-***************************************************************************************/
- const char *osrc = src;
- size_t nleft = dsize;
-
- /* Copy as many bytes as will fit. */
- if (nleft != 0) {
- while (--nleft != 0) {
- if ((*dst++ = *src++) == '\0')
- break;
- }
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src. */
- if (nleft == 0) {
- if (dsize != 0)
- *dst = '\0'; /* NUL-terminate dst */
- while (*src++)
- ;
- }
-
- return(src - osrc - 1); /* count does not include NUL */
-}
-
-
-
/*****************************************************************************/
char *pj_chomp (char *c) {
/******************************************************************************
@@ -261,7 +211,9 @@ consuming their surrounding whitespace.
/* Eliminate prefix '+', only if preceeded by whitespace */
/* (i.e. keep it in 1.23e+08) */
- if ((i > 0) && ('+'==c[j]) && isspace (c[i]))
+ if ((i > 0) && ('+'==c[j]) && ws)
+ c[j] = ' ';
+ if ((i==0) && ('+'==c[j]))
c[j] = ' ';
if (isspace (c[j]) || ';'==c[j]) {