]> git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
MingW32 compilation works now.
[wxWidgets.git] / src / common / utilscmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utilscmn.cpp
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "utils.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/defs.h"
25 #include "wx/utils.h"
26 #include "wx/window.h"
27 #include "wx/menu.h"
28 #include "wx/frame.h"
29 #include "wx/msgdlg.h"
30 #include "wx/textdlg.h"
31 #endif
32
33 #include <ctype.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #if !defined(__WATCOMC__)
38 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
39 #include <errno.h>
40 #endif
41 #endif
42 #include <time.h>
43 #ifndef __MWERKS__
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #endif
47
48 #ifdef __SALFORDC__
49 #include <clib.h>
50 #endif
51
52 // Pattern matching code.
53 // Yes, this path is deliberate (for Borland compilation)
54 #ifdef wx_mac /* MATTHEW: [5] Mac doesn't like paths with "/" */
55 #include "glob.inc"
56 #else
57 #include "../common/glob.inc"
58 #endif
59
60 #ifdef __WXMSW__
61 #include "windows.h"
62 #endif
63
64 #define _MAXPATHLEN 500
65
66 extern wxChar *wxBuffer;
67
68 // ----------------------------------------------------------------------------
69 // private functions
70 // ----------------------------------------------------------------------------
71
72 static wxWindow *wxFindWindowByLabel1(const wxString& title, wxWindow * parent);
73 static wxWindow *wxFindWindowByName1 (const wxString& title, wxWindow * parent);
74
75 #ifdef __WXMAC__
76 int strcasecmp(const char *str_1, const char *str_2)
77 {
78 register char c1, c2;
79 do {
80 c1 = tolower(*str_1++);
81 c2 = tolower(*str_2++);
82 } while ( c1 && (c1 == c2) );
83
84 return c1 - c2;
85 }
86
87 int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
88 {
89
90 register char c1, c2;
91 while( maxchar--)
92 {
93 c1 = tolower(*str_1++);
94 c2 = tolower(*str_2++);
95
96 if ( !c1 || c1!=c2 )
97 return c1 - c2;
98
99 } ;
100
101 return 0 ;
102
103 }
104 #endif
105 #ifdef __VMS__
106 // we have no strI functions under VMS, therefore I have implemented
107 // an inefficient but portable version: convert copies of strings to lowercase
108 // and then use the normal comparison
109 static void myLowerString(char *s)
110 {
111 while(*s){
112 if(isalpha(*s)) *s = (char)tolower(*s);
113 s++;
114 }
115 }
116
117 int strcasecmp(const char *str_1, const char *str_2)
118 {
119 char *temp1 = new char[strlen(str_1)+1];
120 char *temp2 = new char[strlen(str_2)+1];
121 strcpy(temp1,str_1);
122 strcpy(temp2,str_2);
123 myLowerString(temp1);
124 myLowerString(temp2);
125
126 int result = strcmp(temp1,temp2);
127 delete[] temp1;
128 delete[] temp2;
129
130 return(result);
131 }
132
133 int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
134 {
135 char *temp1 = new char[strlen(str_1)+1];
136 char *temp2 = new char[strlen(str_2)+1];
137 strcpy(temp1,str_1);
138 strcpy(temp2,str_2);
139 myLowerString(temp1);
140 myLowerString(temp2);
141
142 int result = strncmp(temp1,temp2,maxchar);
143 delete[] temp1;
144 delete[] temp2;
145
146 return(result);
147 }
148 #endif
149
150 #ifdef __WINDOWS__
151
152 #ifndef __GNUWIN32__
153 #ifndef __MWERKS__
154 #define strcasecmp stricmp
155 #define strncasecmp strnicmp
156 #else
157 #define strcasecmp _stricmp
158 #define strncasecmp _strnicmp
159 #endif
160 #endif
161
162 #else
163
164 #ifdef __EMX__
165 #define strcasecmp stricmp
166 #define strncasecmp strnicmp
167 #endif
168
169 // This declaration is missing in SunOS!
170 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
171 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
172 extern "C"
173 {
174 int strcasecmp (const char *, const char *);
175 int strncasecmp (const char *, const char *, size_t);
176 }
177 #endif
178 #endif /* __WXMSW__ */
179
180
181 wxChar *
182 copystring (const wxChar *s)
183 {
184 if (s == NULL) s = _T("");
185 size_t len = wxStrlen (s) + 1;
186
187 wxChar *news = new wxChar[len];
188 memcpy (news, s, len * sizeof(wxChar)); // Should be the fastest
189
190 return news;
191 }
192
193 // Id generation
194 static long wxCurrentId = 100;
195
196 long
197 wxNewId (void)
198 {
199 return wxCurrentId++;
200 }
201
202 long
203 wxGetCurrentId(void) { return wxCurrentId; }
204
205 void
206 wxRegisterId (long id)
207 {
208 if (id >= wxCurrentId)
209 wxCurrentId = id + 1;
210 }
211
212 void
213 StringToFloat (wxChar *s, float *number)
214 {
215 if (s && *s && number)
216 *number = (float) wxStrtod (s, (wxChar **) NULL);
217 }
218
219 void
220 StringToDouble (wxChar *s, double *number)
221 {
222 if (s && *s && number)
223 *number = wxStrtod (s, (wxChar **) NULL);
224 }
225
226 wxChar *
227 FloatToString (float number, const wxChar *fmt)
228 {
229 static wxChar buf[256];
230
231 // sprintf (buf, "%.2f", number);
232 wxSprintf (buf, fmt, number);
233 return buf;
234 }
235
236 wxChar *
237 DoubleToString (double number, const wxChar *fmt)
238 {
239 static wxChar buf[256];
240
241 wxSprintf (buf, fmt, number);
242 return buf;
243 }
244
245 void
246 StringToInt (wxChar *s, int *number)
247 {
248 if (s && *s && number)
249 *number = (int) wxStrtol (s, (wxChar **) NULL, 10);
250 }
251
252 void
253 StringToLong (wxChar *s, long *number)
254 {
255 if (s && *s && number)
256 *number = wxStrtol (s, (wxChar **) NULL, 10);
257 }
258
259 wxChar *
260 IntToString (int number)
261 {
262 static wxChar buf[20];
263
264 wxSprintf (buf, _T("%d"), number);
265 return buf;
266 }
267
268 wxChar *
269 LongToString (long number)
270 {
271 static wxChar buf[20];
272
273 wxSprintf (buf, _T("%ld"), number);
274 return buf;
275 }
276
277 // Array used in DecToHex conversion routine.
278 static wxChar hexArray[] = _T("0123456789ABCDEF");
279
280 // Convert 2-digit hex number to decimal
281 int wxHexToDec(const wxString& buf)
282 {
283 int firstDigit, secondDigit;
284
285 if (buf.GetChar(0) >= _T('A'))
286 firstDigit = buf.GetChar(0) - _T('A') + 10;
287 else
288 firstDigit = buf.GetChar(0) - _T('0');
289
290 if (buf.GetChar(1) >= _T('A'))
291 secondDigit = buf.GetChar(1) - _T('A') + 10;
292 else
293 secondDigit = buf.GetChar(1) - _T('0');
294
295 return firstDigit * 16 + secondDigit;
296 }
297
298 // Convert decimal integer to 2-character hex string
299 void wxDecToHex(int dec, wxChar *buf)
300 {
301 int firstDigit = (int)(dec/16.0);
302 int secondDigit = (int)(dec - (firstDigit*16.0));
303 buf[0] = hexArray[firstDigit];
304 buf[1] = hexArray[secondDigit];
305 buf[2] = 0;
306 }
307
308 // Convert decimal integer to 2-character hex string
309 wxString wxDecToHex(int dec)
310 {
311 wxChar buf[3];
312 wxDecToHex(dec, buf);
313 return wxString(buf);
314 }
315
316 // Match a string INDEPENDENT OF CASE
317 bool
318 StringMatch (char *str1, char *str2, bool subString, bool exact)
319 {
320 if (str1 == NULL || str2 == NULL)
321 return FALSE;
322 if (str1 == str2)
323 return TRUE;
324
325 if (subString)
326 {
327 int len1 = strlen (str1);
328 int len2 = strlen (str2);
329 int i;
330
331 // Search for str1 in str2
332 // Slow .... but acceptable for short strings
333 for (i = 0; i <= len2 - len1; i++)
334 {
335 if (strncasecmp (str1, str2 + i, len1) == 0)
336 return TRUE;
337 }
338 }
339 else if (exact)
340 {
341 if (strcasecmp (str1, str2) == 0)
342 return TRUE;
343 }
344 else
345 {
346 int len1 = strlen (str1);
347 int len2 = strlen (str2);
348
349 if (strncasecmp (str1, str2, wxMin (len1, len2)) == 0)
350 return TRUE;
351 }
352
353 return FALSE;
354 }
355
356 // Don't synthesize KeyUp events holding down a key and producing
357 // KeyDown events with autorepeat. On by default and always on
358 // on in wxMSW. wxGTK version in utilsgtk.cpp.
359 #ifndef __WXGTK__
360 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
361 {
362 return TRUE; // detectable auto-repeat is the only mode MSW supports
363 }
364 #endif
365
366 // Return the current date/time
367 // [volatile]
368 wxString wxNow( void )
369 {
370 time_t now = time((time_t *) NULL);
371 char *date = ctime(&now);
372 date[24] = '\0';
373 return wxString(date);
374 }
375
376 /*
377 * Strip out any menu codes
378 */
379
380 wxChar *wxStripMenuCodes (wxChar *in, wxChar *out)
381 {
382 if (!in)
383 return (wxChar *) NULL;
384
385 if (!out)
386 out = copystring(in);
387
388 wxChar *tmpOut = out;
389
390 while (*in)
391 {
392 if (*in == _T('&'))
393 {
394 // Check && -> &, &x -> x
395 if (*++in == _T('&'))
396 *out++ = *in++;
397 }
398 else if (*in == _T('\t'))
399 {
400 // Remove all stuff after \t in X mode, and let the stuff as is
401 // in Windows mode.
402 // Accelerators are handled in wx_item.cc for Motif, and are not
403 // YET supported in XView
404 break;
405 }
406 else
407 *out++ = *in++;
408 } // while
409
410 *out = _T('\0');
411
412 return tmpOut;
413 }
414
415 wxString wxStripMenuCodes(const wxString& str)
416 {
417 wxChar *buf = new wxChar[str.Length() + 1];
418 wxStripMenuCodes(WXSTRINGCAST str, buf);
419 wxString str1(buf);
420 delete[] buf;
421 return str1;
422 }
423
424 /*
425 * Window search functions
426 *
427 */
428
429 /*
430 * If parent is non-NULL, look through children for a label or title
431 * matching the specified string. If NULL, look through all top-level windows.
432 *
433 */
434
435 wxWindow *
436 wxFindWindowByLabel (const wxString& title, wxWindow * parent)
437 {
438 if (parent)
439 {
440 return wxFindWindowByLabel1(title, parent);
441 }
442 else
443 {
444 for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
445 node;
446 node = node->GetNext() )
447 {
448 wxWindow *win = node->GetData();
449 wxWindow *retwin = wxFindWindowByLabel1 (title, win);
450 if (retwin)
451 return retwin;
452 } // for()
453
454 }
455 return (wxWindow *) NULL;
456 }
457
458 // Recursive
459 static wxWindow *
460 wxFindWindowByLabel1 (const wxString& title, wxWindow * parent)
461 {
462 if (parent)
463 {
464 if (parent->GetLabel() == title)
465 return parent;
466 }
467
468 if (parent)
469 {
470 for ( wxWindowList::Node * node = parent->GetChildren().GetFirst();
471 node;
472 node = node->GetNext() )
473 {
474 wxWindow *win = (wxWindow *)node->GetData();
475 wxWindow *retwin = wxFindWindowByLabel1 (title, win);
476 if (retwin)
477 return retwin;
478 }
479
480 }
481
482 return (wxWindow *) NULL; // Not found
483 }
484
485 /*
486 * If parent is non-NULL, look through children for a name
487 * matching the specified string. If NULL, look through all top-level windows.
488 *
489 */
490
491 wxWindow *
492 wxFindWindowByName (const wxString& title, wxWindow * parent)
493 {
494 if (parent)
495 {
496 return wxFindWindowByName1 (title, parent);
497 }
498 else
499 {
500 for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
501 node;
502 node = node->GetNext() )
503 {
504 wxWindow *win = node->GetData();
505 wxWindow *retwin = wxFindWindowByName1 (title, win);
506 if (retwin)
507 return retwin;
508 }
509
510 }
511
512 // Failed? Try by label instead.
513 return wxFindWindowByLabel(title, parent);
514 }
515
516 // Recursive
517 static wxWindow *
518 wxFindWindowByName1 (const wxString& title, wxWindow * parent)
519 {
520 if (parent)
521 {
522 if ( parent->GetName() == title )
523 return parent;
524 }
525
526 if (parent)
527 {
528 for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ())
529 {
530 wxWindow *win = (wxWindow *) node->Data ();
531 wxWindow *retwin = wxFindWindowByName1 (title, win);
532 if (retwin)
533 return retwin;
534 } // for()
535
536 }
537
538 return (wxWindow *) NULL; // Not found
539
540 }
541
542 // Returns menu item id or -1 if none.
543 int
544 wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& itemString)
545 {
546 wxMenuBar *menuBar = frame->GetMenuBar ();
547 if (!menuBar)
548 return -1;
549 return menuBar->FindMenuItem (menuString, itemString);
550 }
551
552 /*
553 On Fri, 21 Jul 1995, Paul Craven wrote:
554
555 > Is there a way to find the path of running program's executable? I can get
556 > my home directory, and the current directory, but I don't know how to get the
557 > executable directory.
558 >
559
560 The code below (warty as it is), does what you want on most Unix,
561 DOS, and Mac platforms (it's from the ALS Prolog main).
562
563 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
564 ||==== Voice: +1 (617)965-9191 Newton Centre,
565 || FAX: +1 (617)965-1636 MA 02159 USA
566 Email: ken@als.com WWW: http://www.als.com
567 ------------------------------------------------------------------------
568 */
569
570 // This code is commented out but it may be integrated with wxWin at
571 // a later date, after testing. Thanks Ken!
572 #if 0
573
574 /*--------------------------------------------------------------------*
575 | whereami is given a filename f in the form: whereami(argv[0])
576 | It returns the directory in which the executable file (containing
577 | this code [main.c] ) may be found. A dot will be returned to indicate
578 | the current directory.
579 *--------------------------------------------------------------------*/
580
581 static void
582 whereami(name)
583 char *name;
584 {
585 register char *cutoff = NULL; /* stifle -Wall */
586 register char *s;
587 register char *t;
588 int cc;
589 char ebuf[4096];
590
591 /*
592 * See if the file is accessible either through the current directory
593 * or through an absolute path.
594 */
595
596 if (access(name, R_OK) == 0) {
597
598 /*-------------------------------------------------------------*
599 * The file was accessible without any other work. But the current
600 * working directory might change on us, so if it was accessible
601 * through the cwd, then we should get it for later accesses.
602 *-------------------------------------------------------------*/
603
604 t = imagedir;
605 if (!absolute_pathname(name)) {
606 #if defined(DOS) || defined(__WIN32__)
607 int drive;
608 char *newrbuf;
609
610 newrbuf = imagedir;
611 #ifndef __DJGPP__
612 if (*(name + 1) == ':') {
613 if (*name >= 'a' && *name <= 'z')
614 drive = (int) (*name - 'a' + 1);
615 else
616 drive = (int) (*name - 'A' + 1);
617 *newrbuf++ = *name;
618 *newrbuf++ = *(name + 1);
619 *newrbuf++ = DIR_SEPARATOR;
620 }
621 else {
622 drive = 0;
623 *newrbuf++ = DIR_SEPARATOR;
624 }
625 if (getcwd(newrbuf, drive) == 0) { /* } */
626 #else
627 if (getcwd(newrbuf, 1024) == 0) { /* } */
628 #endif
629 #else /* DOS */
630 #ifdef HAVE_GETWD
631 if (getwd(imagedir) == 0) { /* } */
632 #else /* !HAVE_GETWD */
633 if (getcwd(imagedir, 1024) == 0) {
634 #endif /* !HAVE_GETWD */
635 #endif /* DOS */
636 fatal_error(FE_GETCWD, 0);
637 }
638 for (; *t; t++) /* Set t to end of buffer */
639 ;
640 if (*(t - 1) == DIR_SEPARATOR) /* leave slash if already
641 * last char
642 */
643 cutoff = t - 1;
644 else {
645 cutoff = t; /* otherwise put one in */
646 *t++ = DIR_SEPARATOR;
647 }
648 }
649 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
650 else
651 (*t++ = DIR_SEPARATOR);
652 #endif
653
654 /*-------------------------------------------------------------*
655 * Copy the rest of the string and set the cutoff if it was not
656 * already set. If the first character of name is a slash, cutoff
657 * is not presently set but will be on the first iteration of the
658 * loop below.
659 *-------------------------------------------------------------*/
660
661 for ((*name == DIR_SEPARATOR ? (s = name+1) : (s = name));;) {
662 if (*s == DIR_SEPARATOR)
663 cutoff = t;
664 if (!(*t++ = *s++))
665 break;
666 }
667
668 }
669 else {
670
671 /*-------------------------------------------------------------*
672 * Get the path list from the environment. If the path list is
673 * inaccessible for any reason, leave with fatal error.
674 *-------------------------------------------------------------*/
675
676 #ifdef __MAC__
677 if ((s = getenv("Commands")) == (char *) 0)
678 #else
679 if ((s = getenv("PATH")) == (char *) 0)
680 #endif
681 fatal_error(FE_PATH, 0);
682
683 /*
684 * Copy path list into ebuf and set the source pointer to the
685 * beginning of this buffer.
686 */
687
688 strcpy(ebuf, s);
689 s = ebuf;
690
691 for (;;) {
692 t = imagedir;
693 while (*s && *s != PATH_SEPARATOR)
694 *t++ = *s++;
695 if (t > imagedir && *(t - 1) == DIR_SEPARATOR)
696 ; /* do nothing -- slash already is in place */
697 else
698 *t++ = DIR_SEPARATOR; /* put in the slash */
699 cutoff = t - 1; /* set cutoff */
700 strcpy(t, name);
701 if (access(imagedir, R_OK) == 0)
702 break;
703
704 if (*s)
705 s++; /* advance source pointer */
706 else
707 fatal_error(FE_INFND, 0);
708 }
709
710 }
711
712 /*-------------------------------------------------------------*
713 | At this point the full pathname should exist in imagedir and
714 | cutoff should be set to the final slash. We must now determine
715 | whether the file name is a symbolic link or not and chase it down
716 | if it is. Note that we reuse ebuf for getting the link.
717 *-------------------------------------------------------------*/
718
719 #ifdef HAVE_SYMLINK
720 while ((cc = readlink(imagedir, ebuf, 512)) != -1) {
721 ebuf[cc] = 0;
722 s = ebuf;
723 if (*s == DIR_SEPARATOR) {
724 t = imagedir;
725 }
726 else {
727 t = cutoff + 1;
728 }
729 for (;;) {
730 if (*s == DIR_SEPARATOR)
731 cutoff = t; /* mark the last slash seen */
732 if (!(*t++ = *s++)) /* copy the character */
733 break;
734 }
735 }
736
737 #endif /* HAVE_SYMLINK */
738
739 strcpy(imagename, cutoff + 1); /* keep the image name */
740 *(cutoff + 1) = 0; /* chop off the filename part */
741 }
742
743 #endif
744 void wxEnableTopLevelWindows(bool enable)
745 {
746 wxWindowList::Node *node;
747 for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
748 node->GetData()->Enable(enable);
749 }
750
751 // Yield to other apps/messages and disable user input
752 bool wxSafeYield(wxWindow *win)
753 {
754 wxEnableTopLevelWindows(FALSE);
755 // always enable ourselves
756 if ( win )
757 win->Enable(TRUE);
758 bool rc = wxYield();
759 wxEnableTopLevelWindows(TRUE);
760 return rc;
761 }
762
763 /*
764 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
765 * since otherwise the generic code may be pulled in unnecessarily.
766 */
767
768 int wxMessageBox(const wxString& message, const wxString& caption, long style,
769 wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y) )
770 {
771 wxMessageDialog dialog(parent, message, caption, style);
772
773 int ans = dialog.ShowModal();
774 switch ( ans )
775 {
776 case wxID_OK:
777 return wxOK;
778 break;
779 case wxID_YES:
780 return wxYES;
781 break;
782 case wxID_NO:
783 return wxNO;
784 break;
785 default:
786 case wxID_CANCEL:
787 return wxCANCEL;
788 break;
789 }
790 return ans;
791 }
792
793 #if wxUSE_TEXTDLG
794 wxString wxGetTextFromUser(const wxString& message, const wxString& caption,
795 const wxString& defaultValue, wxWindow *parent,
796 int x, int y, bool WXUNUSED(centre) )
797 {
798 wxTextEntryDialog dialog(parent, message, caption, defaultValue, wxOK|wxCANCEL, wxPoint(x, y));
799 if (dialog.ShowModal() == wxID_OK)
800 return dialog.GetValue();
801 else
802 return wxString("");
803 }
804 #endif // wxUSE_TEXTDLG
805
806 #ifdef __MWERKS__
807 char *strdup(const char *s)
808 {
809 return strcpy( (char*) malloc( strlen( s ) + 1 ) , s ) ;
810 }
811
812 int isascii( int c )
813 {
814 return ( c >= 0 && c < 128 ) ;
815 }
816 #endif
817
818 // ----------------------------------------------------------------------------
819 // network and user id functions
820 // ----------------------------------------------------------------------------
821
822 // Get Full RFC822 style email address
823 bool wxGetEmailAddress(wxChar *address, int maxSize)
824 {
825 wxString email = wxGetEmailAddress();
826 if ( !email )
827 return FALSE;
828
829 wxStrncpy(address, email, maxSize - 1);
830 address[maxSize - 1] = _T('\0');
831
832 return TRUE;
833 }
834
835 wxString wxGetEmailAddress()
836 {
837 wxString email;
838
839 wxString host = wxGetHostName();
840 if ( !!host )
841 {
842 wxString user = wxGetUserId();
843 if ( !!user )
844 {
845 wxString email(user);
846 email << _T('@') << host;
847 }
848 }
849
850 return email;
851 }
852
853 wxString wxGetUserId()
854 {
855 static const int maxLoginLen = 256; // FIXME arbitrary number
856
857 wxString buf;
858 bool ok = wxGetUserId(buf.GetWriteBuf(maxLoginLen), maxLoginLen);
859 buf.UngetWriteBuf();
860
861 if ( !ok )
862 buf.Empty();
863
864 return buf;
865 }
866
867 wxString wxGetUserName()
868 {
869 static const int maxUserNameLen = 1024; // FIXME arbitrary number
870
871 wxString buf;
872 bool ok = wxGetUserName(buf.GetWriteBuf(maxUserNameLen), maxUserNameLen);
873 buf.UngetWriteBuf();
874
875 if ( !ok )
876 buf.Empty();
877
878 return buf;
879 }
880
881 wxString wxGetHostName()
882 {
883 static const size_t hostnameSize = 257;
884
885 wxString buf;
886 bool ok = wxGetHostName(buf.GetWriteBuf(hostnameSize), hostnameSize);
887
888 buf.UngetWriteBuf();
889
890 if ( !ok )
891 buf.Empty();
892
893 return buf;
894 }
895
896 wxString wxGetFullHostName()
897 {
898 static const size_t hostnameSize = 257;
899
900 wxString buf;
901 bool ok = wxGetFullHostName(buf.GetWriteBuf(hostnameSize), hostnameSize);
902
903 buf.UngetWriteBuf();
904
905 if ( !ok )
906 buf.Empty();
907
908 return buf;
909 }
910