diff options
| author | erco77 <erco@seriss.com> | 2020-08-01 14:35:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-01 14:35:44 -0700 |
| commit | 7abc09ad89b4c3d0c17ee8dc9d02ccd261cd13f2 (patch) | |
| tree | 72e461bac5930f8a319d48a6ea99ba793dd35a8b /src | |
| parent | 7514a73ba759f7fc9965eeef3b92ece899bd7a69 (diff) | |
| parent | e9688822ec68f066f425953278a853e049b93dfb (diff) | |
Merge pull request #116 from erco77/fl_strdup
fl_strdup() implemented + deployed
Diffstat (limited to 'src')
45 files changed, 164 insertions, 85 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d3ef3940c..d5eee5dc8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -157,6 +157,7 @@ set (CPPFILES fl_vertex.cxx screen_xywh.cxx fl_utf8.cxx + fl_string.cxx fl_encoding_latin1.cxx fl_encoding_mac_roman.cxx ) diff --git a/src/Fl_Check_Browser.cxx b/src/Fl_Check_Browser.cxx index 6d802688c..6f286e4d3 100644 --- a/src/Fl_Check_Browser.cxx +++ b/src/Fl_Check_Browser.cxx @@ -18,6 +18,7 @@ #include <stdlib.h> #include "flstring.h" #include <FL/fl_draw.H> +#include <FL/fl_string.h> // fl_strdup() #include <FL/Fl_Check_Browser.H> /* This uses a cache for faster access when you're scanning the list @@ -243,7 +244,7 @@ int Fl_Check_Browser::add(char *s, int b) { p->prev = 0; p->checked = b; p->selected = 0; - p->text = strdup(s?s:""); + p->text = fl_strdup(s?s:""); if (b) { nchecked_++; diff --git a/src/Fl_File_Browser.cxx b/src/Fl_File_Browser.cxx index cb92428dd..da70c8752 100644 --- a/src/Fl_File_Browser.cxx +++ b/src/Fl_File_Browser.cxx @@ -34,6 +34,7 @@ #include "Fl_System_Driver.H" #include <FL/fl_draw.H> #include <FL/filename.H> +#include <FL/fl_string.h> #include <FL/Fl_Image.H> // icon #include <stdio.h> #include <stdlib.h> @@ -387,7 +388,7 @@ Fl_File_Browser::~Fl_File_Browser() { */ void Fl_File_Browser::errmsg(const char* emsg) { if ( errmsg_ ) { free((void*)errmsg_); errmsg_ = NULL; } - errmsg_ = emsg ? strdup(emsg) : NULL; + errmsg_ = emsg ? fl_strdup(emsg) : NULL; } diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx index ec04bd77c..ddbb3e5cd 100644 --- a/src/Fl_File_Chooser2.cxx +++ b/src/Fl_File_Chooser2.cxx @@ -325,6 +325,7 @@ #include <FL/platform.H> #include <FL/Fl_Shared_Image.H> #include <FL/fl_draw.H> +#include <FL/fl_string.h> #include <stdio.h> #include <stdlib.h> @@ -945,7 +946,7 @@ Fl_File_Chooser::filter(const char *p) // I - Pattern(s) if (!p || !*p) p = "*"; // Copy the pattern string... - copyp = strdup(p); + copyp = fl_strdup(p); // Separate the pattern string as necessary... showChoice->clear(); diff --git a/src/Fl_Help_View.cxx b/src/Fl_Help_View.cxx index f6c6407c1..e27f81e37 100644 --- a/src/Fl_Help_View.cxx +++ b/src/Fl_Help_View.cxx @@ -56,6 +56,7 @@ #include <stdlib.h> #include <FL/fl_utf8.h> #include <FL/filename.H> // fl_open_uri() +#include <FL/fl_string.h> // fl_strdup() #include "flstring.h" #include <ctype.h> #include <errno.h> @@ -3404,7 +3405,7 @@ int Fl_Help_View::load(const char *f) "<P>Unable to follow the link \"%s\" - " "%s.</P></BODY>", localname, strerror(errno)); - value_ = strdup(error); + value_ = fl_strdup(error); ret = -1; } @@ -3543,7 +3544,7 @@ Fl_Help_View::value(const char *val) // I - Text to view if (!val) return; - value_ = strdup(val); + value_ = fl_strdup(val); initial_load = 1; format(); diff --git a/src/Fl_Image_Reader.cxx b/src/Fl_Image_Reader.cxx index 1f19379a0..f9a886b0f 100644 --- a/src/Fl_Image_Reader.cxx +++ b/src/Fl_Image_Reader.cxx @@ -22,6 +22,7 @@ #include "Fl_Image_Reader.h" #include <FL/fl_utf8.h> +#include <FL/fl_string.h> #include <stdlib.h> #include <string.h> @@ -40,7 +41,7 @@ int Fl_Image_Reader::open(const char *filename) { if (!filename) return -1; - pName = strdup(filename); + pName = fl_strdup(filename); if ( (pFile = fl_fopen(filename, "rb")) == NULL ) { return -1; } @@ -51,7 +52,7 @@ int Fl_Image_Reader::open(const char *filename) { // Initialize the reader for memory access, name is copied and stored int Fl_Image_Reader::open(const char *imagename, const unsigned char *data) { if (imagename) - pName = strdup(imagename); + pName = fl_strdup(imagename); if (data) { pStart = pData = data; pIsData = 1; diff --git a/src/Fl_MacOS_Sys_Menu_Bar.mm b/src/Fl_MacOS_Sys_Menu_Bar.mm index 7f7abba2e..c589f8118 100644 --- a/src/Fl_MacOS_Sys_Menu_Bar.mm +++ b/src/Fl_MacOS_Sys_Menu_Bar.mm @@ -17,6 +17,7 @@ #if defined(__APPLE__) #include <FL/platform.H> +#include <FL/fl_string.h> #include "drivers/Cocoa/Fl_MacOS_Sys_Menu_Bar_Driver.H" #include "flstring.h" #include <stdio.h> @@ -291,7 +292,7 @@ static void setMenuFlags( NSMenu* mh, int miCnt, const Fl_Menu_Item *m ) static char *remove_ampersand(const char *s) { - char *ret = strdup(s); + char *ret = fl_strdup(s); const char *p = s; char *q = ret; while(*p != 0) { diff --git a/src/Fl_Menu_add.cxx b/src/Fl_Menu_add.cxx index b2282b6f2..d5fdae9c5 100644 --- a/src/Fl_Menu_add.cxx +++ b/src/Fl_Menu_add.cxx @@ -25,6 +25,7 @@ // string with a % sign in it! #include <FL/Fl_Menu_.H> +#include <FL/fl_string.h> #include "flstring.h" #include <stdio.h> #include <stdlib.h> @@ -62,7 +63,7 @@ static Fl_Menu_Item* array_insert( memmove(array+n+1, array+n, sizeof(Fl_Menu_Item)*(size-n)); // create the new item: Fl_Menu_Item* m = array+n; - m->text = text ? strdup(text) : 0; + m->text = text ? fl_strdup(text) : 0; m->shortcut_ = 0; m->callback_ = 0; m->user_data_ = 0; @@ -455,7 +456,7 @@ void Fl_Menu_::replace(int i, const char *str) { if (!alloc) copy(menu_); if (alloc > 1) { free((void *)menu_[i].text); - str = strdup(str?str:""); + str = fl_strdup(str?str:""); } menu_[i].text = str; } diff --git a/src/Fl_Native_File_Chooser_GTK.cxx b/src/Fl_Native_File_Chooser_GTK.cxx index 4de7343b6..16ed1f480 100644 --- a/src/Fl_Native_File_Chooser_GTK.cxx +++ b/src/Fl_Native_File_Chooser_GTK.cxx @@ -25,6 +25,7 @@ #include <FL/Fl_Shared_Image.H> #include <FL/Fl_Image_Surface.H> #include <FL/fl_draw.H> +#include <FL/fl_string.h> #include <dlfcn.h> // for dlopen et al #include "drivers/X11/Fl_X11_System_Driver.H" @@ -110,7 +111,7 @@ private: const char *filter; // a filter string of the chooser pair(Fl_GTK_Native_File_Chooser_Driver* c, const char *f) { running = c; - filter = strdup(f); + filter = fl_strdup(f); }; ~pair() { free((char*)filter); @@ -490,7 +491,7 @@ static char *extract_dir_from_path(const char *path) } if (*path != '/') return NULL; if (dir) free(dir); - dir = strdup(path); + dir = fl_strdup(path); do { char *p = strrchr(dir, '/'); if (p == dir) p++; @@ -710,7 +711,7 @@ int Fl_GTK_Native_File_Chooser_Driver::fl_gtk_chooser_wrapper() GtkFileFilter **filter_tab = NULL; if (_parsedfilt) { filter_tab = new GtkFileFilter*[_nfilters]; - char *filter = strdup(_parsedfilt); + char *filter = fl_strdup(_parsedfilt); p = strtok(filter, "\t"); int count = 0; while (p) { diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm index 0f6191d23..6ae29bee2 100644 --- a/src/Fl_Native_File_Chooser_MAC.mm +++ b/src/Fl_Native_File_Chooser_MAC.mm @@ -27,6 +27,7 @@ #include <FL/Fl_Native_File_Chooser.H> #include <FL/Fl_File_Chooser.H> #include <FL/filename.H> +#include <FL/fl_string.h> #define MAXFILTERS 80 #import <Cocoa/Cocoa.h> @@ -402,7 +403,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::filters() const { #define UNLIKELYPREFIX "___fl_very_unlikely_prefix_" int Fl_Quartz_Native_File_Chooser_Driver::get_saveas_basename(void) { - char *q = strdup( [[[_panel URL] path] UTF8String] ); + char *q = fl_strdup( [[[_panel URL] path] UTF8String] ); if ( !(_options & Fl_Native_File_Chooser::SAVEAS_CONFIRM) ) { const char *d = [[[[_panel URL] path] stringByDeletingLastPathComponent] UTF8String]; int l = (int)strlen(d) + 1; @@ -520,7 +521,7 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) { // correspondingly changes the extension of the output file name { if (fl_mac_os_version < 100600) return; // because of setNameFieldStringValue and nameFieldStringValue - char *s = strdup([[(NSPopUpButton*)sender titleOfSelectedItem] UTF8String]); + char *s = fl_strdup([[(NSPopUpButton*)sender titleOfSelectedItem] UTF8String]); if (!s) return; char *p = strchr(s, '('); if (!p) p = s; @@ -724,7 +725,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() { char *p = _filt_patt[_filt_value]; char *q = strchr(p, '.'); if(!q) q = p-1; do q++; while (*q==' ' || *q=='{'); - p = strdup(q); + p = fl_strdup(q); q = strchr(p, ','); if (q) *q = 0; [_panel setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]]; free(p); diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx index e7327012a..11851c0de 100644 --- a/src/Fl_Preferences.cxx +++ b/src/Fl_Preferences.cxx @@ -25,6 +25,7 @@ #include <stdlib.h> #include <stdarg.h> #include <FL/fl_utf8.h> +#include <FL/fl_string.h> #include "flstring.h" @@ -636,7 +637,7 @@ char Fl_Preferences::get( const char *key, char *&text, const char *defaultValue } if ( !v ) v = defaultValue; if ( v ) - text = strdup( v ); + text = fl_strdup( v ); else text = 0; return ( v != defaultValue ); @@ -911,9 +912,9 @@ Fl_Preferences::RootNode::RootNode( Fl_Preferences *prefs, Root root, const char root_(root) { char *filename = Fl::system_driver()->preference_rootnode(prefs, root, vendor, application); - filename_ = filename ? strdup(filename) : 0L; - vendor_ = strdup(vendor); - application_ = strdup(application); + filename_ = filename ? fl_strdup(filename) : 0L; + vendor_ = fl_strdup(vendor); + application_ = fl_strdup(application); read(); } @@ -931,14 +932,14 @@ Fl_Preferences::RootNode::RootNode( Fl_Preferences *prefs, const char *path, con vendor = "unknown"; if (!application) { application = "unknown"; - filename_ = strdup(path); + filename_ = fl_strdup(path); } else { char filename[ FL_PATH_MAX ]; filename[0] = 0; snprintf(filename, sizeof(filename), "%s/%s.prefs", path, application); - filename_ = strdup(filename); + filename_ = fl_strdup(filename); } - vendor_ = strdup(vendor); - application_ = strdup(application); + vendor_ = fl_strdup(vendor); + application_ = fl_strdup(application); read(); } @@ -1112,7 +1113,7 @@ char Fl_Preferences::RootNode::getPath( char *path, int pathlen ) { // create a node that represents a group // - path must be a single word, prferable alnum(), dot and underscore only. Space is ok. Fl_Preferences::Node::Node( const char *path ) { - if ( path ) path_ = strdup( path ); else path_ = 0; + if ( path ) path_ = fl_strdup( path ); else path_ = 0; child_ = 0; next_ = 0; parent_ = 0; entry_ = 0; nEntry_ = NEntry_ = 0; @@ -1225,7 +1226,7 @@ void Fl_Preferences::Node::setParent( Node *pn ) { pn->child_ = this; sprintf( nameBuffer, "%s/%s", pn->path_, path_ ); free( path_ ); - path_ = strdup( nameBuffer ); + path_ = fl_strdup( nameBuffer ); } // find the corresponding root node @@ -1242,7 +1243,7 @@ Fl_Preferences::RootNode *Fl_Preferences::Node::findRoot() { // add a child to this node and set its path (try to find it first...) Fl_Preferences::Node *Fl_Preferences::Node::addChild( const char *path ) { sprintf( nameBuffer, "%s/%s", path_, path ); - char *name = strdup( nameBuffer ); + char *name = fl_strdup( nameBuffer ); Node *nd = find( name ); free( name ); updateIndex(); @@ -1258,7 +1259,7 @@ void Fl_Preferences::Node::set( const char *name, const char *value ) if ( strcmp( value, entry_[i].value ) != 0 ) { if ( entry_[i].value ) free( entry_[i].value ); - entry_[i].value = strdup( value ); + entry_[i].value = fl_strdup( value ); dirty_ = 1; } lastEntrySet = i; @@ -1269,8 +1270,8 @@ void Fl_Preferences::Node::set( const char *name, const char *value ) NEntry_ = NEntry_ ? NEntry_*2 : 10; entry_ = (Entry*)realloc( entry_, NEntry_ * sizeof(Entry) ); } - entry_[ nEntry_ ].name = strdup( name ); - entry_[ nEntry_ ].value = value?strdup( value ):0; + entry_[ nEntry_ ].name = fl_strdup( name ); + entry_[ nEntry_ ].value = value?fl_strdup(value):0; lastEntrySet = nEntry_; nEntry_++; dirty_ = 1; diff --git a/src/Fl_SVG_Image.cxx b/src/Fl_SVG_Image.cxx index ca9644fe1..93aaee28b 100644 --- a/src/Fl_SVG_Image.cxx +++ b/src/Fl_SVG_Image.cxx @@ -21,6 +21,7 @@ #include <FL/Fl_SVG_Image.H> #include <FL/fl_utf8.h> #include <FL/fl_draw.H> +#include <FL/fl_string.h> #include "Fl_Screen_Driver.H" #include <stdio.h> #include <stdlib.h> @@ -152,7 +153,7 @@ void Fl_SVG_Image::init_(const char *filename, const char *in_filedata, Fl_SVG_I if (!filedata) ld(ERR_FILE_ACCESS); } else { // XXX: Make internal copy -- nsvgParse() modifies filedata during parsing (!) - filedata = in_filedata ? strdup(in_filedata) : NULL; + filedata = in_filedata ? fl_strdup(in_filedata) : NULL; } if (filedata) { counted_svg_image_->svg_image = nsvgParse(filedata, "px", 96); diff --git a/src/Fl_System_Driver.H b/src/Fl_System_Driver.H index 77a58971f..73f197f95 100644 --- a/src/Fl_System_Driver.H +++ b/src/Fl_System_Driver.H @@ -98,6 +98,9 @@ public: virtual int putenv(const char *var) {return -1;} virtual int open(const char* f, int oflags, int pmode) {return -1;} + // implement these to support cross-platform string operations + virtual char *strdup(const char *s) {return NULL;} + // Note: the default implementation ignores the 'binary' argument. // Some platforms (notably Windows) may use this argument. virtual int open_ext(const char* f, int binary, int oflags, int pmode) { diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index 9691d7a4a..476f1ec61 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -17,6 +17,7 @@ #include <stdio.h> #include <stdlib.h> #include <FL/fl_utf8.h> +#include <FL/fl_string.h> #include "flstring.h" #include <ctype.h> #include <FL/Fl.H> @@ -462,7 +463,7 @@ int Fl_Text_Buffer::undo(int *cursorPos) if (xlen && ilen) { undobuffersize(ilen + 1); undobuffer[ilen] = 0; - char *tmp = strdup(undobuffer); + char *tmp = fl_strdup(undobuffer); replace(b, undoat, tmp); if (cursorPos) *cursorPos = mCursorPosHint; diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index 8b4450cfa..34f6f38ac 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -20,10 +20,11 @@ #include <stdio.h> #include <stdlib.h> #include <FL/fl_utf8.h> +#include <FL/fl_string.h> // fl_strdup() #include "flstring.h" #include <limits.h> #include <ctype.h> -#include <string.h> // strdup() +#include <string.h> #include <FL/Fl.H> #include <FL/platform.H> #include <FL/Fl_Text_Buffer.H> @@ -171,7 +172,7 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l) linenumber_fgcolor_ = FL_INACTIVE_COLOR; linenumber_bgcolor_ = 53; // ~90% gray linenumber_align_ = FL_ALIGN_RIGHT; - linenumber_format_ = strdup("%d"); + linenumber_format_ = fl_strdup("%d"); // Method calls -- only AFTER all members initialized color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR); @@ -326,7 +327,7 @@ Fl_Align Fl_Text_Display::linenumber_align() const { */ void Fl_Text_Display::linenumber_format(const char* val) { if ( linenumber_format_ ) free((void*)linenumber_format_); - linenumber_format_ = val ? strdup(val) : 0; + linenumber_format_ = val ? fl_strdup(val) : 0; } /** diff --git a/src/Fl_Tooltip.cxx b/src/Fl_Tooltip.cxx index 53fcdb18f..220e4603d 100644 --- a/src/Fl_Tooltip.cxx +++ b/src/Fl_Tooltip.cxx @@ -18,10 +18,10 @@ #include <FL/fl_draw.H> #include <FL/Fl_Menu_Window.H> #include <FL/Fl.H> +#include <FL/fl_string.h> #include "Fl_System_Driver.H" #include <stdio.h> -#include <string.h> // strdup() float Fl_Tooltip::delay_ = 1.0f; float Fl_Tooltip::hidedelay_ = 12.0f; @@ -379,7 +379,7 @@ void Fl_Widget::copy_tooltip(const char *text) { if (flags() & COPIED_TOOLTIP) free((void *)(tooltip_)); if (text) { set_flag(COPIED_TOOLTIP); - tooltip_ = strdup(text); + tooltip_ = fl_strdup(text); } else { clear_flag(COPIED_TOOLTIP); tooltip_ = (char *)0; diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx index ec1d4816e..5dab99c2a 100644 --- a/src/Fl_Tree.cxx +++ b/src/Fl_Tree.cxx @@ -6,6 +6,7 @@ #include <FL/Fl_Tree.H> #include <FL/Fl_Preferences.H> +#include <FL/fl_string.h> ////////////////////// // Fl_Tree.cxx @@ -2643,7 +2644,7 @@ void Fl_Tree::load(Fl_Preferences &prefs) { n = prefs.entries(); for (i=0; i<n; i++) { // We must remove all fwd slashes in the key and value strings. Replace with backslash. - char *key = strdup(prefs.entry(i)); + char *key = fl_strdup(prefs.entry(i)); int kn = (int) strlen(key); for (j=0; j<kn; j++) { if (key[j]=='/') key[j]='\\'; diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx index 3df432ca7..98611278f 100644 --- a/src/Fl_Tree_Item.cxx +++ b/src/Fl_Tree_Item.cxx @@ -3,10 +3,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <FL/Fl.H> #include <FL/Fl_Widget.H> #include <FL/Fl_Tree_Item.H> #include <FL/Fl_Tree_Prefs.H> #include <FL/Fl_Tree.H> +#include <FL/fl_string.h> ////////////////////// // Fl_Tree_Item.cxx @@ -103,7 +105,7 @@ Fl_Tree_Item::~Fl_Tree_Item() { /// Copy constructor. Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Item *o) { _tree = o->_tree; - _label = o->label() ? strdup(o->label()) : 0; + _label = o->label() ? fl_strdup(o->label()) : 0; _labelfont = o->labelfont(); _labelsize = o->labelsize(); _labelfgcolor = o->labelfgcolor(); @@ -154,7 +156,7 @@ void Fl_Tree_Item::show_self(const char *indent) const { /// void Fl_Tree_Item::label(const char *name) { if ( _label ) { free((void*)_label); _label = 0; } - _label = name ? strdup(name) : 0; + _label = name ? fl_strdup(name) : 0; recalc_tree(); // may change label geometry } diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index 25a4bb981..8b4de1a2a 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -19,6 +19,7 @@ #include <FL/Fl_Group.H> #include <FL/Fl_Tooltip.H> #include <FL/fl_draw.H> +#include <FL/fl_string.h> #include <stdlib.h> #include "flstring.h" @@ -291,7 +292,7 @@ void Fl_Widget::copy_label(const char *a) { if ((flags() & COPIED_LABEL) && (label_.value == a)) return; if (a) { - label(strdup(a)); + label(fl_strdup(a)); set_flag(COPIED_LABEL); } else { label(0); diff --git a/src/Fl_Window.cxx b/src/Fl_Window.cxx index dee4b32df..a999511d2 100644 --- a/src/Fl_Window.cxx +++ b/src/Fl_Window.cxx @@ -28,6 +28,7 @@ #include <FL/Fl_Window.H> #include <FL/Fl_Tooltip.H> #include <FL/fl_draw.H> +#include <FL/fl_string.h> #include <stdlib.h> #include "flstring.h" @@ -225,7 +226,7 @@ void Fl_Window::default_xclass(const char *xc) default_xclass_ = 0L; } if (xc) { - default_xclass_ = strdup(xc); + default_xclass_ = fl_strdup(xc); } } @@ -260,7 +261,7 @@ void Fl_Window::xclass(const char *xc) xclass_ = 0L; } if (xc) { - xclass_ = strdup(xc); + xclass_ = fl_strdup(xc); if (!default_xclass_) { default_xclass(xc); } diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 934dd2f78..50c658e8b 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -30,6 +30,7 @@ extern "C" { #include <FL/Fl_Printer.H> #include <FL/fl_draw.H> #include <FL/Fl_Rect.H> +#include <FL/fl_string.h> #include "drivers/Quartz/Fl_Quartz_Graphics_Driver.H" #include "drivers/Quartz/Fl_Quartz_Copy_Surface_Driver.H" #include "drivers/Cocoa/Fl_Cocoa_Screen_Driver.H" @@ -1587,7 +1588,7 @@ static void drain_dropped_files_list() { return; } NSString *s = (NSString*)[dropped_files_list objectAtIndex:0]; - char *fname = strdup([s UTF8String]); + char *fname = fl_strdup([s UTF8String]); [dropped_files_list removeObjectAtIndex:0]; if ([dropped_files_list count] == 0) { [dropped_files_list release]; @@ -3529,7 +3530,7 @@ static int get_plain_text_from_clipboard(int clipboard) [data length], [found isEqualToString:@"public.utf16-plain-text"] ? kCFStringEncodingUnicode : kCFStringEncodingMacRoman, false); - aux_c = strdup([auxstring UTF8String]); + aux_c = fl_strdup([auxstring UTF8String]); [auxstring release]; len = strlen(aux_c) + 1; } diff --git a/src/Fl_get_system_colors.cxx b/src/Fl_get_system_colors.cxx index e1b7fc2f4..73388c835 100644 --- a/src/Fl_get_system_colors.cxx +++ b/src/Fl_get_system_colors.cxx @@ -21,6 +21,7 @@ #include <FL/platform.H> #include <FL/math.h> #include <FL/fl_utf8.h> +#include <FL/fl_string.h> #include "flstring.h" #include <stdio.h> #include <stdlib.h> @@ -163,9 +164,9 @@ int Fl::scheme(const char *s) { if (s) { if (!fl_ascii_strcasecmp(s, "none") || !fl_ascii_strcasecmp(s, "base") || !*s) s = 0; - else if (!fl_ascii_strcasecmp(s, "gtk+")) s = strdup("gtk+"); - else if (!fl_ascii_strcasecmp(s, "plastic")) s = strdup("plastic"); - else if (!fl_ascii_strcasecmp(s, "gleam")) s = strdup("gleam"); + else if (!fl_ascii_strcasecmp(s, "gtk+")) s = fl_strdup("gtk+"); + else if (!fl_ascii_strcasecmp(s, "plastic")) s = fl_strdup("plastic"); + else if (!fl_ascii_strcasecmp(s, "gleam")) s = fl_strdup("gleam"); else s = 0; } if (scheme_) free((void*)scheme_); diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index d234f7afd..e0d5c9f4b 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -60,6 +60,7 @@ void fl_cleanup_dc_list(void); #include "drivers/WinAPI/Fl_WinAPI_Screen_Driver.H" #include "drivers/GDI/Fl_GDI_Graphics_Driver.H" #include <FL/fl_utf8.h> +#include <FL/fl_string.h> #include <FL/Fl_Window.H> #include <FL/fl_draw.H> #include <FL/Enumerations.H> @@ -1919,7 +1920,7 @@ public: NName += 5; name = (char **)realloc(name, NName * sizeof(char *)); } - name[nName++] = strdup(n); + name[nName++] = fl_strdup(n); } char has_name(const char *n) { int i; diff --git a/src/Makefile b/src/Makefile index 123aef0c0..c1409a59a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -160,7 +160,8 @@ CPPFILES = \ fl_symbols.cxx \ fl_vertex.cxx \ screen_xywh.cxx \ - fl_utf8.cxx + fl_utf8.cxx \ + fl_string.cxx OBJCPPFILES = \ Fl_cocoa.mm \ 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 <FL/platform.H> #include <FL/fl_draw.H> +#include <FL/fl_string.h> #include <jni.h> @@ -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 <FL/fl_string.h> #include "../../Fl_System_Driver.H" #include <stdarg.h> @@ -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 <FL/Fl.H> #include <FL/fl_utf8.h> +#include <FL/fl_string.h> #include <FL/filename.H> #include <FL/Fl_File_Browser.H> #include <FL/Fl_File_Icon.H> @@ -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 <FL/platform.H> #include <FL/fl_ask.H> #include <FL/fl_draw.H> +#include <FL/fl_string.h> #import <Cocoa/Cocoa.h> 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 <stdio.h> #include <stdlib.h> +#include <FL/fl_string.h> // 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 <FL/Fl_File_Browser.H> #include <FL/Fl_File_Icon.H> #include <FL/filename.H> +#include <FL/fl_string.h> #include <FL/Fl.H> #include <locale.h> #include <stdio.h> @@ -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 <FL/Fl_PostScript.H> #include <FL/Fl_Native_File_Chooser.H> #include "../../Fl_System_Driver.H" +#include <FL/fl_string.h> #include <stdarg.h> #include <time.h> @@ -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 <FL/Fl.H> #include <FL/platform.H> #include <FL/fl_utf8.h> // for fl_utf8toUtf16() +#include <FL/fl_string.h> // 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 <FL/Fl_RGB_Image.H> #include <FL/Fl_Pixmap.H> #include <FL/Fl_Bitmap.H> +#include <FL/fl_string.h> + 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_, "<defs><image id=\"%s\" ", name); @@ -547,7 +549,7 @@ static void term_destination(jpeg_compress_struct *cinfo) { void Fl_SVG_Graphics_Driver::define_rgb_jpeg(Fl_RGB_Image *rgb, const char *name, int x, int y) { 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_, "<defs><image id=\"%s\" ", name); diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index 91b230d5f..0dd12ca17 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -24,6 +24,7 @@ #include "../../Fl_System_Driver.H" #include <stdarg.h> +#include <string.h> // 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..025d4ee37 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 <FL/Fl.H> #include <FL/fl_utf8.h> +#include <FL/fl_string.h> // fl_strdup() #include <FL/filename.H> #include <FL/Fl_File_Browser.H> #include <FL/Fl_File_Icon.H> @@ -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..6dcaee06d 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 <FL/Fl_File_Browser.H> +#include <FL/fl_string.h> // fl_strdup #include "../../flstring.h" #include <X11/Xlib.h> @@ -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 <FL/Fl.H> #include <FL/fl_draw.H> #include <FL/platform.H> +#include <FL/fl_string.h> #include "Fl_Font.H" #include <stdio.h> @@ -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..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,6 +20,7 @@ #include "Fl_Xlib_Graphics_Driver.H" #include <FL/Fl.H> #include <FL/fl_draw.H> +#include <FL/fl_string.h> // fl_strdup() #include <FL/platform.H> #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++; } diff --git a/src/filename_absolute.cxx b/src/filename_absolute.cxx index 67beb50c3..e39da321d 100644 --- a/src/filename_absolute.cxx +++ b/src/filename_absolute.cxx @@ -22,6 +22,7 @@ #include <FL/filename.H> #include <FL/Fl.H> +#include <FL/fl_string.h> #include "Fl_System_Driver.H" #include <stdlib.h> #include "flstring.h" @@ -162,7 +163,7 @@ Fl_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' || !isdirsep(*from)) { diff --git a/src/fl_ask.cxx b/src/fl_ask.cxx index ecd853bd5..f711a9f1d 100644 --- a/src/fl_ask.cxx +++ b/src/fl_ask.cxx @@ -29,6 +29,7 @@ #include "flstring.h" #include <FL/Fl.H> +#include <FL/fl_string.h> #include <FL/fl_ask.H> @@ -664,7 +665,7 @@ void fl_message_title_default(const char *title) { message_title_default = 0; } if (title) - message_title_default = strdup(title); + message_title_default = fl_strdup(title); } /** @} */ diff --git a/src/fl_string.cxx b/src/fl_string.cxx new file mode 100644 index 000000000..c53c0e21f --- /dev/null +++ b/src/fl_string.cxx @@ -0,0 +1,34 @@ +/* + * Platform agnostic string portability functions for the Fast Light Tool Kit (FLTK). + * + * Copyright 2020 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 + * file is missing or damaged, see the license at: + * + * https://www.fltk.org/COPYING.php + * + * Please see the following page on how to report bugs and issues: + * + * https://www.fltk.org/bugs.php + */ + +#include <FL/fl_string.h> +#include <string.h> // strdup/_strdup +#include "Fl_System_Driver.H" + +/** + Cross platform interface to POSIX function strdup(). + + The fl_strdup() function returns a pointer to a new string which is + a duplicate of the string 's'. Memory for the new string is obtained + with malloc(3), and can be freed with free(3). + + Implementation: + - POSIX: strdup() + - WinAPI: _strdup() + */ +char *fl_strdup(const char *s) { + return Fl::system_driver()->strdup(s); +} diff --git a/src/flstring.h b/src/flstring.h index fa3111226..d902c0a9f 100644 --- a/src/flstring.h +++ b/src/flstring.h @@ -52,10 +52,6 @@ * Some of these functions are also defined in ISO C99... */ -# if defined(_MSC_VER) -# define strdup _strdup -# endif /* _MSC_VER */ - # if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) # define strcasecmp(s,t) _stricmp((s), (t)) # define strncasecmp(s,t,n) _strnicmp((s), (t), (n)) diff --git a/src/print_panel.cxx b/src/print_panel.cxx index 617b9938d..7b29991fa 100644 --- a/src/print_panel.cxx +++ b/src/print_panel.cxx @@ -36,6 +36,7 @@ #include "../src/flstring.h" #include <FL/Fl_Preferences.H> #include <FL/Fl_Int_Input.H> +#include <FL/fl_string.h> static Fl_Double_Window *print_panel=(Fl_Double_Window *)0; static Fl_Group *print_panel_controls=(Fl_Group *)0; @@ -541,7 +542,7 @@ printing_style print_load() { // return whether SystemV or BSD printing style is } *qptr = '\0'; - print_choice->add(qname, 0, 0, (void *)strdup(name), 0); + print_choice->add(qname, 0, 0, (void *)fl_strdup(name), 0); } else if (!strncmp(line, "system default destination: ", 28)) { if (sscanf(line + 28, "%s", defname) != 1) defname[0] = '\0'; } @@ -553,7 +554,7 @@ printing_style print_load() { // return whether SystemV or BSD printing style is while (fgets(line, sizeof(line),lpstat)) { // get names of all known printers if (*line == '#' || (p = strchr(line, '|')) == NULL) continue; *p = 0; - print_choice->add(line, 0, 0, (void *)strdup(line), 0); + print_choice->add(line, 0, 0, (void *)fl_strdup(line), 0); style = BSD; *p = '|'; while (1) { diff --git a/src/xutf8/utf8Wrap.c b/src/xutf8/utf8Wrap.c index e26aef15f..4a2bbc990 100644 --- a/src/xutf8/utf8Wrap.c +++ b/src/xutf8/utf8Wrap.c @@ -21,6 +21,7 @@ #include "../Xutf8.h" #include <X11/Xlib.h> +#include <FL/fl_string.h> // fl_strdup() #include <ctype.h> #include <stdlib.h> #include <string.h> @@ -215,7 +216,7 @@ find_best_font(Display *dpy, list = XListFonts(dpy, *name, 1, &cnt); if (cnt && list) { free(*name); - *name = strdup(list[0]); + *name = fl_strdup(list[0]); s = XLoadQueryFont(dpy, *name); XFreeFontNames(list); return s; |
