Use setenv(), fix warnings
PATCH 1/1 Use setenv(), fix warnings
- Use setenv() instead of putenv()
- Fix -Wundef -Wold-style-definition warnings
- Make pll_free() static
---
cache.h | 2 +- exec_cmd.c | 2 +- fetch-pack.c | 2 +- fsck-objects.c | 4 ++-- pack-objects.c | 2 +- pack-redundant.c | 4 ++-- path.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)
4001390d41ffd2c816cead47c256e598bedff452
cache.h +1 -1
@@ -10,7 +10,7 @@#define deflateBound (c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)#endif -#if defined(DT_UNKNOWN ) && !NO_D_TYPE_IN_DIRENT +#if defined(DT_UNKNOWN ) && !defined(NO_D_TYPE_IN_DIRENT )#define DTYPE (de) ((de)->d_type)#else #undef DT_UNKNOWN
exec_cmd.c +1 -1
@@ -13,7 +13,7 @@ void git_set_exec_path(const char *exec_/* Returns the highest-priority, location to look for git programs. */ -const char *git_exec_path () +const char *git_exec_path (void ) {const char *env;
fetch-pack.c +1 -1
@@ -82,7 +82,7 @@ static void mark_common(struct commit *cGet the next rev to send, ignoring the common. */ -static const unsigned char *get_rev () +static const unsigned char *get_rev (void ) {struct commit *commit =NULL ;
fsck-objects.c +2 -2
@@ -20,7 +20,7 @@ static int check_strict = 0;static int keep_cache_objects =0 ;static unsigned char head_sha1[20 ]; -#if NO_D_INO_IN_DIRENT +#ifdef NO_D_INO_IN_DIRENT #define SORT_DIRENT 0#define DIRENT_SORT_HINT (de) 0#else
@@ -483,7 +483,7 @@ int main(int argc, char **argv)if (standalone && check_full)die ("Only one of --standalone or --full can be used." );if (standalone) -putenv ("GIT_ALTERNATE_OBJECT_DIRECTORIES=" ); +setenv ("GIT_ALTERNATE_OBJECT_DIRECTORIES" ,"" ,1 );fsck_head_link ();fsck_object_dir (get_object_directory ());
pack-objects.c +1 -1
@@ -768,7 +768,7 @@ static int sha1_sort(const struct objectreturn memcmp (a->sha1, b->sha1,20 ); } -static struct object_entry **create_final_object_list () +static struct object_entry **create_final_object_list (void ) {struct object_entry **list;int i, j;
pack-redundant.c +2 -2
@@ -45,7 +45,7 @@ static inline void llist_item_put(struct free_nodes = item; } -static inline struct llist_item *llist_item_get () +static inline struct llist_item *llist_item_get (void ) {struct llist_item *new;if ( free_nodes ) {
@@ -275,7 +275,7 @@ static void cmp_two_packs(struct pack_li } } -void pll_free (struct pll *l) +static void pll_free (struct pll *l) {struct pll *old;struct pack_list *opl;
path.c +1 -1
@@ -243,7 +243,7 @@ char *enter_repo(char *path, int strict)if (access ("objects" ,X_OK ) ==0 &&access ("refs" ,X_OK ) ==0 &&validate_symref ("HEAD" ) ==0 ) { -putenv ("GIT_DIR=." ); +setenv ("GIT_DIR" ,"." ,1 );check_repository_format ();return path; }
Signature · 1 line
1.2.1
Quoted 3 lines · Timo Hirvonen
- Use
setenv()instead ofputenv()
- Fix -Wundef -Wold-style-definition warnings
- Makepll_free()static
I think the last one makes sense, and I can see why some people may prefer -Wundef but I am not sure about the first one. Care to defend why we should prefer setenv()? IIRC, initially we did not use setenv() anywhere because certain platforms only had putenv().
fsck-objects.c int main(int argc, char **argv) · line 486
Quoted 7 lines
fsck-objects.c +1
-1@@ -483,7 +483,7 @@ int main(int argc, char **argv)if (standalone && check_full)die ("Only one of --standalone or --full can be used." );if (standalone) -putenv ("GIT_ALTERNATE_OBJECT_DIRECTORIES=" ); +setenv ("GIT_ALTERNATE_OBJECT_DIRECTORIES" ,"" ,1 );
For platforms with only putenv we did this; here, what we really wanted to do was unsetenv.
Quoted 11 lines · On Sun, 26 Feb 2006 10:06:41 -0800 Junio C Hamano <[email protected]> wrote:
Quoted 3 lines · Timo Hirvonen
- Use
setenv()instead ofputenv()
- Fix -Wundef -Wold-style-definition warnings
- Makepll_free()staticI think the last one makes sense, and I can see why some people may prefer -Wundef but I am not sure about the first one. Care to defend why we should prefer
setenv()? IIRC, initially we did not usesetenv()anywhere because certain platforms only hadputenv().
I was confused by putenv(3) man page. I thought it wanted malloc'ed strings (no 'const' in the parameter -> warning). It appears that statically allocated strings are accepted but _automatic_ variables aren't. I noticed setenv is now in compat/ so I though it was good idea to use it.
Sorry for the noise.
Quoted 10 lines
fsck-objects.c int main(int argc, char **argv) · line 486
Quoted 7 lines
fsck-objects.c +1
-1@@ -483,7 +483,7 @@ int main(int argc, char **argv)if (standalone && check_full)die ("Only one of --standalone or --full can be used." );if (standalone) -putenv ("GIT_ALTERNATE_OBJECT_DIRECTORIES=" ); +setenv ("GIT_ALTERNATE_OBJECT_DIRECTORIES" ,"" ,1 );For platforms with only putenv we did this; here, what we really wanted to do was unsetenv.
putenv(3):
"If the argument string is of the form name, and does not contain an =' character, then the variable name` is removed from the environment."
So the variable is emptied, not removed. But usually empty environment variables are treated as if they didn't exist...
Signature · 1 line
http://onion.dynserv.net/~timo/
And Timo Hirvonen writes:
- It appears that statically allocated strings are accepted but
- _automatic_ variables aren't.
The putenv()-ed string has to exist as long as the environment does. You can twiddle the environment just by twiddling the string you registered. What fun!
- I noticed setenv is now in compat/ so I though it was good idea
- to use it.
All uses of putenv() originally were setenv(). I finally realized a compat/setenv.c was better than playing whack-a-setenv on every release... (Ah, hindsight.)
Note that the current compat/setenv.c _LEAKS MEMORY_ on purpose. Because putenv() requires the string to stay around, we can't ever free it. I hope any library implementing bits of git (libgitbit?) avoids setting environment variables.
- So the variable is emptied, not removed. But usually empty environment
- variables are treated as if they didn't exist...
More specifically, git treats both "" and NULL as empty, or at least it did last time I checked.
Jason
Quoted 7 lines · Timo Hirvonen
putenv(3):
"If the argumentstringis of the formname, and does not contain an=' character, then the variablename` is removed from the environment."So the variable is emptied, not removed. But usually empty environment variables are treated as if they didn't exist...
Yes we were aware of that when we did it.