From 2141c63628a831d3f53dad7035c94028f8d0d629 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Tue, 21 Jul 2020 20:15:41 -0700 Subject: Implement + deploy fl_strdup() --- src/drivers/Android/Fl_Android_Application.cxx | 3 ++- src/drivers/Android/Fl_Android_System_Driver.H | 3 ++- src/drivers/Android/Fl_Android_System_Driver.cxx | 3 ++- src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm | 3 ++- src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx | 9 +++++---- src/drivers/Posix/Fl_Posix_System_Driver.H | 2 ++ src/drivers/Posix/Fl_Posix_System_Driver.cxx | 3 ++- src/drivers/PostScript/Fl_PostScript.cxx | 3 ++- src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx | 5 +++-- src/drivers/SVG/Fl_SVG_File_Surface.cxx | 12 +++++++----- src/drivers/WinAPI/Fl_WinAPI_System_Driver.H | 3 +++ src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 3 ++- src/drivers/X11/Fl_X11_System_Driver.cxx | 3 ++- src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx | 5 +++-- src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx | 11 ++++++----- 15 files changed, 45 insertions(+), 26 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/Android/Fl_Android_Application.cxx b/src/drivers/Android/Fl_Android_Application.cxx index 87053543a..793ebb5a1 100644 --- a/src/drivers/Android/Fl_Android_Application.cxx +++ b/src/drivers/Android/Fl_Android_Application.cxx @@ -25,6 +25,7 @@ #include #include +#include #include @@ -376,7 +377,7 @@ void *Fl_Android_Application::thread_entry(void* param) pthread_cond_broadcast(&pCond); pthread_mutex_unlock(&pMutex); - char *argv[] = { strdup(pActivity->obbPath), 0 }; + char *argv[] = { fl_strdup(pActivity->obbPath), 0 }; main(1, argv); destroy(); diff --git a/src/drivers/Android/Fl_Android_System_Driver.H b/src/drivers/Android/Fl_Android_System_Driver.H index 198d7a2b3..84f8262a4 100644 --- a/src/drivers/Android/Fl_Android_System_Driver.H +++ b/src/drivers/Android/Fl_Android_System_Driver.H @@ -22,6 +22,7 @@ #ifndef FL_ANDROID_SYSTEM_DRIVER_H #define FL_ANDROID_SYSTEM_DRIVER_H +#include #include "../../Fl_System_Driver.H" #include @@ -46,7 +47,7 @@ public: virtual void fatal(const char *format, va_list args); virtual char *utf2mbcs(const char *s); virtual char *getenv(const char *var); - virtual int putenv(const char *var) { return ::putenv(strdup(var)); } + virtual int putenv(const char *var) { return ::putenv(fl_strdup(var)); } virtual int open(const char *fnam, int oflags, int pmode); virtual int open_ext(const char *fnam, int binary, int oflags, int pmode); virtual FILE *fopen(const char *fnam, const char *mode); diff --git a/src/drivers/Android/Fl_Android_System_Driver.cxx b/src/drivers/Android/Fl_Android_System_Driver.cxx index 0fa9671c5..d25e96425 100644 --- a/src/drivers/Android/Fl_Android_System_Driver.cxx +++ b/src/drivers/Android/Fl_Android_System_Driver.cxx @@ -18,6 +18,7 @@ #include "Fl_Android_System_Driver.H" #include #include +#include #include #include #include @@ -545,7 +546,7 @@ Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename char *newslash; // Directory separator const char *slash; // Directory separator char *cwd = 0L, *cwd_buf = 0L; - if (base) cwd = cwd_buf = strdup(base); + if (base) cwd = cwd_buf = fl_strdup(base); // return if "from" is not an absolute path if (from[0] == '\0' || diff --git a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm index ab3d90fb0..2a0955622 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm +++ b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm @@ -26,6 +26,7 @@ #include #include #include +#include #import typedef OSStatus (*PMSessionSetDocumentFormatGeneration_type)( @@ -196,7 +197,7 @@ int Fl_Cocoa_Printer_Driver::begin_job (int pagecount, int *frompage, int *topag if (perr_message) { NSError *nserr = [NSError errorWithDomain:NSCocoaErrorDomain code:status userInfo:nil]; NSString *s = [nserr localizedDescription]; - if (s) *perr_message = strdup([s UTF8String]); + if (s) *perr_message = fl_strdup([s UTF8String]); } return 2; } diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx index 1e2b492f3..3371c4e08 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx +++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx @@ -41,6 +41,7 @@ #include #include +#include // This function fills in the FLTK font table with all the fonts that // are found on the X server. It tries to place the fonts into families @@ -98,12 +99,12 @@ enumcbw(CONST LOGFONTW *lpelf, if (!strcmp(Fl::get_font_name((Fl_Font)i),n)) {free(n);return 1;} char buffer[LF_FACESIZE + 1]; strcpy(buffer+1, n); - buffer[0] = ' '; Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer)); + buffer[0] = ' '; Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer)); if (lpelf->lfWeight <= 400) - buffer[0] = 'B', Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer)); - buffer[0] = 'I'; Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer)); + buffer[0] = 'B', Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer)); + buffer[0] = 'I'; Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer)); if (lpelf->lfWeight <= 400) - buffer[0] = 'P', Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer)); + buffer[0] = 'P', Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer)); free(n); return 1; } /* enumcbw */ diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index 55255b83f..3f4cf72c8 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -38,6 +38,7 @@ - directory and file access - system time and system timer - multithreading + - string management */ class Fl_Posix_System_Driver : public Fl_System_Driver @@ -74,6 +75,7 @@ public: virtual const char *home_directory_name() { return ::getenv("HOME"); } virtual int dot_file_hidden() {return 1;} virtual void gettime(time_t *sec, int *usec); + virtual char* strdup(const char *s) {return ::strdup(s);} }; #endif // FL_POSIX_SYSTEM_DRIVER_H diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx index d39ea6c82..9f255f3d0 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx +++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ void *Fl_Posix_System_Driver::dlopen(const char *filename) ptr = double_dlopen(filename); # ifdef __APPLE_CC__ // allows testing on Darwin + XQuartz + fink if (!ptr) { - char *f_dylib = strdup(filename); + char *f_dylib = fl_strdup(filename); strcpy(strrchr(f_dylib, '.'), ".dylib"); char path[FL_PATH_MAX]; sprintf(path, "/sw/lib/%s", f_dylib); diff --git a/src/drivers/PostScript/Fl_PostScript.cxx b/src/drivers/PostScript/Fl_PostScript.cxx index b7b10da8e..5adf20562 100644 --- a/src/drivers/PostScript/Fl_PostScript.cxx +++ b/src/drivers/PostScript/Fl_PostScript.cxx @@ -23,6 +23,7 @@ #include #include #include "../../Fl_System_Driver.H" +#include #include #include @@ -83,7 +84,7 @@ int Fl_PostScript_File_Device::begin_job (int pagecount, enum Fl_Paged_Device::P Fl_PostScript_Graphics_Driver *ps = driver(); ps->output = fl_fopen(fnfc.filename(), "w"); if(ps->output == NULL) return 2; - ps->ps_filename_ = strdup(fnfc.filename()); + ps->ps_filename_ = fl_strdup(fnfc.filename()); ps->start_postscript(pagecount, format, layout); this->set_current(); return 0; diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx index e6352af2a..fe43f0c6c 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx @@ -79,6 +79,7 @@ #include #include #include // for fl_utf8toUtf16() +#include // fl_strdup() Fl_Fontdesc* fl_fonts = NULL; @@ -682,7 +683,7 @@ Fl_Font Fl_Quartz_Graphics_Driver::ADD_SUFFIX(set_fonts, _CoreText)(const char* CFRelease(font); static char fname[200]; CFStringGetCString(cfname, fname, sizeof(fname), kCFStringEncodingUTF8); - tabfontnames[i] = strdup(fname); // never free'ed + tabfontnames[i] = fl_strdup(fname); // never free'ed CFRelease(cfname); } CFRelease(arrayref); @@ -869,7 +870,7 @@ Fl_Font Fl_Quartz_Graphics_Driver::ADD_SUFFIX(set_fonts, _ATSU)(const char* xsta oName[511] = 0; else oName[actualLength] = 0; - Fl::set_font((Fl_Font)(fl_free_font++), strdup(oName)); + Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(oName)); // free(oName); } free(oFontIDs); diff --git a/src/drivers/SVG/Fl_SVG_File_Surface.cxx b/src/drivers/SVG/Fl_SVG_File_Surface.cxx index d0946da8b..5106c6486 100644 --- a/src/drivers/SVG/Fl_SVG_File_Surface.cxx +++ b/src/drivers/SVG/Fl_SVG_File_Surface.cxx @@ -28,6 +28,8 @@ #include #include #include +#include + extern "C" { #if defined(HAVE_LIBPNG) # ifdef HAVE_PNG_H @@ -137,7 +139,7 @@ Fl_SVG_Graphics_Driver::Fl_SVG_Graphics_Driver(FILE *f) { clip_count_ = 0; clip_ = NULL; user_dash_array_ = 0; - dasharray_ = strdup("none"); + dasharray_ = fl_strdup("none"); p_size = 0; p = NULL; last_rgb_name_ = NULL; @@ -205,13 +207,13 @@ void Fl_SVG_Graphics_Driver::compute_dasharray(float s, char *dashes) { sprintf(dasharray_+strlen(dasharray_), "%.3f,", (*p)/s); } dasharray_[strlen(dasharray_) - 1] = 0; - if (user_dash_array_ != dashes) user_dash_array_ = strdup(dashes); + if (user_dash_array_ != dashes) user_dash_array_ = fl_strdup(dashes); return; } int dash_part = line_style_ & 0xFF; if (dash_part == FL_SOLID) { if (dasharray_ && strcmp(dasharray_, "none")) free(dasharray_); - dasharray_ = strdup("none"); + dasharray_ = fl_strdup("none"); } else { int cap_part = (line_style_ & 0xF00); bool is_flat = (cap_part == FL_CAP_FLAT || cap_part == 0); @@ -458,7 +460,7 @@ void Fl_SVG_Graphics_Driver::define_rgb_png(Fl_RGB_Image *rgb, const char *name, } if (name) { if (last_rgb_name_) free(last_rgb_name_); - last_rgb_name_ = strdup(name); + last_rgb_name_ = fl_strdup(name); } float f = rgb->data_w() > rgb->data_h() ? float(rgb->w()) / rgb->data_w(): float(rgb->h()) / rgb->data_h(); if (name) fprintf(out_, "data_w() > rgb->data_h() ? float(rgb->w()) / rgb->data_w(): float(rgb->h()) / rgb->data_h(); if (name) fprintf(out_, " +#include // strdup /* Move everything here that manages the system interface. @@ -34,6 +35,7 @@ - directory and file access - system time and system timer - multithreading + - string management */ class Fl_WinAPI_System_Driver : public Fl_System_Driver @@ -116,6 +118,7 @@ public: virtual void remove_fd(int, int when); virtual void remove_fd(int); virtual void gettime(time_t *sec, int *usec); + virtual char* strdup(const char *s) { return ::_strdup(s); } }; #endif // FL_WINAPI_SYSTEM_DRIVER_H diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx index 592e192e3..d37ec62ff 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx @@ -18,6 +18,7 @@ #include "Fl_WinAPI_System_Driver.H" #include #include +#include // fl_strdup() #include #include #include @@ -548,7 +549,7 @@ Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename char *newslash; // Directory separator const char *slash; // Directory separator char *cwd = 0L, *cwd_buf = 0L; - if (base) cwd = cwd_buf = strdup(base); + if (base) cwd = cwd_buf = fl_strdup(base); // return if "from" is not an absolute path if (from[0] == '\0' || diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx index 28827bcfc..8a308bdb8 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.cxx +++ b/src/drivers/X11/Fl_X11_System_Driver.cxx @@ -17,6 +17,7 @@ #include "Fl_X11_System_Driver.H" #include +#include // fl_strdup #include "../../flstring.h" #include @@ -592,7 +593,7 @@ bool Fl_X11_System_Driver::probe_for_GTK(int major, int minor, void **ptr_gtk) { char *before = NULL; // record in "before" the calling program's current locale char *p = setlocale(LC_ALL, NULL); - if (p) before = strdup(p); + if (p) before = fl_strdup(p); int ac = 0; init_f(&ac, NULL); // may change the locale if (before) { diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx index 8b3784566..9251eafe4 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include "Fl_Font.H" #include @@ -305,7 +306,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* xstarname) { if (fl_fonts[j].name && !strcmp(fl_fonts[j].name, p)) break; } else */{ j = fl_free_font++; - if (p == canon) p = strdup(p); else used_xlist = 1; + if (p == canon) p = fl_strdup(p); else used_xlist = 1; Fl::set_font((Fl_Font)j, p); break; } @@ -521,7 +522,7 @@ static char *put_font_size(const char *n, int size) const char *f; char *name; int nbf = 1; - name = strdup(n); + name = fl_strdup(n); while (name[i]) { if (name[i] == ',') {nbf++; name[i] = '\0';} i++; diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx index 5a80904ab..6b42b880a 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx @@ -20,6 +20,7 @@ #include "Fl_Xlib_Graphics_Driver.H" #include #include +#include // fl_strdup() #include #include "Fl_Font.H" @@ -423,7 +424,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name) } else { // The listed name has been modified - full_list[j] = strdup(first); + full_list[j] = fl_strdup(first); // Free the font name storage free (font); } @@ -451,7 +452,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name) make_raw_name(xft_name, full_list[j]); // NOTE: This just adds on AFTER the default fonts - no attempt is made // to identify already loaded fonts. Is this bad? - stored_name = strdup(xft_name); + stored_name = fl_strdup(xft_name); Fl::set_font((Fl_Font)(j + FL_FREE_FONT), stored_name); fl_free_font ++; @@ -552,7 +553,7 @@ static XftFont* fontopen(const char* name, /*Fl_Fontsize*/double size, bool core } if(comma_count) { // multiple comma-separated names were passed - char *local_name = strdup(name); // duplicate the full name so we can edit the copy + char *local_name = fl_strdup(name); // duplicate the full name so we can edit the copy char *curr = local_name; // points to first name in string char *nxt; // next name in string do { @@ -681,7 +682,7 @@ static XftFont* fontopen(const char* name, /*Fl_Fontsize*/double size, bool core * XLFD's to construct a "super-pattern" that incorporates attributes from all * XLFD's and use that to perform a XftFontMatch(). Maybe... */ - char *local_name = strdup(name); + char *local_name = fl_strdup(name); if(comma_count) { // This means we were passed multiple XLFD's char *pc = strchr(local_name, ','); *pc = 0; // terminate the XLFD at the first comma @@ -1087,7 +1088,7 @@ static XFontStruct* load_xfont_for_xft2(Fl_Graphics_Driver *driver) { const char *weight = wt_med; // no specifc weight requested - accept any char slant = 'r'; // regular non-italic by default char xlfd[128]; // we will put our synthetic XLFD in here - char *pc = strdup(fl_fonts[fnum].name); // what font were we asked for? + char *pc = fl_strdup(fl_fonts[fnum].name); // what font were we asked for? #if USE_PANGO char *p = pc + 1; while (*p) { *p = tolower(*p); p++; } -- cgit v1.2.3 From b4095880125b2f0d1d56c80a2bbf3fb0f6f98cb9 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Tue, 21 Jul 2020 23:57:45 -0700 Subject: Remove unneeded strdup from example, fold tabs --- src/drivers/WinAPI/Fl_WinAPI_System_Driver.H | 2 +- src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 2 +- src/drivers/X11/Fl_X11_System_Driver.cxx | 2 +- src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index 049e6c114..0dd12ca17 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -24,7 +24,7 @@ #include "../../Fl_System_Driver.H" #include -#include // strdup +#include // strdup /* Move everything here that manages the system interface. diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx index d37ec62ff..025d4ee37 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx @@ -18,7 +18,7 @@ #include "Fl_WinAPI_System_Driver.H" #include #include -#include // fl_strdup() +#include // fl_strdup() #include #include #include diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx index 8a308bdb8..6dcaee06d 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.cxx +++ b/src/drivers/X11/Fl_X11_System_Driver.cxx @@ -17,7 +17,7 @@ #include "Fl_X11_System_Driver.H" #include -#include // fl_strdup +#include // fl_strdup #include "../../flstring.h" #include diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx index 6b42b880a..5c88ec100 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx @@ -20,7 +20,7 @@ #include "Fl_Xlib_Graphics_Driver.H" #include #include -#include // fl_strdup() +#include // fl_strdup() #include #include "Fl_Font.H" -- cgit v1.2.3