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