From f3896460d64f06a6203da05bdcdabf7e133c8f10 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 12 Nov 2017 18:00:45 +0000 Subject: Replace chdir() with new wrapper fl_chdir(). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12558 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- fluid/fluid.cxx | 18 ++++---- src/filename_absolute.cxx | 6 +-- test/demo.cxx | 103 ++++++++++++++++++++++------------------------ 3 files changed, 59 insertions(+), 68 deletions(-) diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index 39a3f37ab..b75e8f571 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -48,13 +48,6 @@ #include "function_panel.h" #include "template_panel.h" -// Visual C++ 2005 incorrectly displays a warning about the use of -// POSIX APIs on Windows, which is supposed to be POSIX compliant... -// Some of these functions are also defined in ISO C99... -#if defined(_MSC_VER) -# define chdir _chdir -#endif // _MSC_VER - #if defined(WIN32) && !defined(__CYGWIN__) # include # include @@ -135,15 +128,18 @@ void goto_source_dir() { pwd = fl_getcwd(0, FL_PATH_MAX); if (!pwd) {fprintf(stderr, "getwd : %s\n",strerror(errno)); return;} } - if (chdir(buffer) < 0) {fprintf(stderr, "Can't chdir to %s : %s\n", - buffer, strerror(errno)); return;} + if (fl_chdir(buffer) < 0) { + fprintf(stderr, "Can't chdir to %s : %s\n", buffer, strerror(errno)); + return; + } in_source_dir = 1; } void leave_source_dir() { if (!in_source_dir) return; - if (chdir(pwd)<0) {fprintf(stderr, "Can't chdir to %s : %s\n", - pwd, strerror(errno));} + if (fl_chdir(pwd) < 0) { + fprintf(stderr, "Can't chdir to %s : %s\n", pwd, strerror(errno)); + } in_source_dir = 0; } diff --git a/src/filename_absolute.cxx b/src/filename_absolute.cxx index 7d96c6cbc..1f1c7ddbe 100644 --- a/src/filename_absolute.cxx +++ b/src/filename_absolute.cxx @@ -3,7 +3,7 @@ // // Filename expansion routines for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2010 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -34,7 +34,7 @@ inline int isdirsep(char c) {return c == '/';} \code #include [..] - chdir("/var/tmp"); + fl_chdir("/var/tmp"); fl_filename_absolute(out, sizeof(out), "foo.txt"); // out="/var/tmp/foo.txt" fl_filename_absolute(out, sizeof(out), "./foo.txt"); // out="/var/tmp/foo.txt" fl_filename_absolute(out, sizeof(out), "../log/messages"); // out="/var/log/messages" @@ -92,7 +92,7 @@ int Fl_System_Driver::filename_absolute(char *to, int tolen, const char *from) { \code #include [..] - chdir("/var/tmp/somedir"); // set cwd to /var/tmp/somedir + fl_chdir("/var/tmp/somedir"); // set cwd to /var/tmp/somedir [..] char out[FL_PATH_MAX]; fl_filename_relative(out, sizeof(out), "/var/tmp/somedir/foo.txt"); // out="foo.txt", return=1 diff --git a/test/demo.cxx b/test/demo.cxx index 16376f9b5..86887d585 100644 --- a/test/demo.cxx +++ b/test/demo.cxx @@ -20,28 +20,28 @@ #include #include -// *FIXME* Implement fl_chdir() and fl_putenv() ! -// *FIXME* Check whether directory related headers can be removed (i.e. not -// *FIXME* included) if fl_chdir() is implemented and called in demo.cxx +// *FIXME* +// Implement fl_putenv(). Then remove the following comment +// and the #define's of fl_putenv below // Visual C++ 2005 incorrectly displays a warning about the use of // POSIX APIs on Windows, which is supposed to be POSIX compliant... -# if defined(_MSC_VER) -# define chdir _chdir -# define putenv _putenv -# endif // _MSC_VER -#if defined(WIN32) && !defined(__CYGWIN__) -# include -#elif defined __APPLE__ -#include -#include // for chdir() -#include -#include // for system() -#include +#if defined(_MSC_VER) +# define fl_putenv _putenv #else -# include +# define fl_putenv putenv +#endif // _MSC_VER + +// *FIXME* To do: +// Check whether '#include ' can be removed since chdir() +// has been replaced with fl_chdir() (AlbrechtS, Nov 12, 2017) + +#if defined __APPLE__ +#include +#include // no longer necessary with fl_chdir() ? #endif + #include #include #include @@ -137,27 +137,24 @@ typedef struct { MENU menus[MAXMENU]; int mennumb = 0; -int find_menu(const char* nnn) -/* Returns the number of a given menu name. */ -{ +/* Return the number of a given menu name. */ +int find_menu(const char* nnn) { int i; for (i=0; i buf) { buf[c-buf] = 0; - if (chdir(buf)==-1) { /* ignore */ } + if (fl_chdir(buf) == -1) { /* ignore */ } } push_menu("@main"); form->show(argc,argv); @@ -462,4 +458,3 @@ int main(int argc, char **argv) { // // End of "$Id$". // - -- cgit v1.2.3