From b5ae06cc09a95f5c2d66f601ccee6b3193750231 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 31 Jan 2008 16:48:02 +0000 Subject: [PATCH] 2008-01-31 17:40 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * bin/hb-func.sh + Updated for lib name change. Please test & review. * source/rtl/net.c * include/hbapi.h + Added hb_netname() and hb_username() low level versions of NETNAME() and hb_USERNAME(). --- harbour/ChangeLog | 10 ++++++ harbour/bin/hb-func.sh | 8 ++--- harbour/include/hbapi.h | 2 ++ harbour/source/rtl/net.c | 68 +++++++++++++++++++++++----------------- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9a4b290eb5..ed2fcf9ea3 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,16 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2008-01-31 17:40 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * bin/hb-func.sh + + Updated for lib name change. + Please test & review. + + * source/rtl/net.c + * include/hbapi.h + + Added hb_netname() and hb_username() low level versions + of NETNAME() and hb_USERNAME(). + 2008-01-31 17:40 UTC+0100 Ryszard Glab * config/w32/mingw32.cf * fixed library name mainstd -> hbmainstd diff --git a/harbour/bin/hb-func.sh b/harbour/bin/hb-func.sh index 8d70336f55..ac5df01149 100755 --- a/harbour/bin/hb-func.sh +++ b/harbour/bin/hb-func.sh @@ -71,7 +71,7 @@ mk_hbgetlibs() then libs="$libs gtwin" fi - echo -n "vm pp rtl rdd dbffpt dbfcdx dbfntx hsx hbsix usrrdd ${HB_DB_DRVEXT} macro common lang codepage gtcrs gtsln gtxvt gtxwc gtalleg gtcgi gtstd gtpca gttrm $libs gtwvt gtgui gtdos gtos2 debug profiler compiler hbpcre" + echo -n "hbvm hbpp hbrtl hbrdd rddfpt rddcdx rddntx hbhsx hbsix hbusrrdd ${HB_DB_DRVEXT} hbmacro hbcommon hblang hbcpage gtcrs gtsln gtxvt gtxwc gtalleg gtcgi gtstd gtpca gttrm $libs gtwvt gtgui gtdos gtos2 hbdebug profiler hbcplr hbpcre" else echo -n "$@" fi @@ -88,7 +88,7 @@ mk_hbgetlibsctb() then libs="$libs gtwin" fi - echo -n "$libs hbrddads hbct hbnf hbzlib hbtip xhb hbgd hbodbc hbpg hbmysql hbrddado hbw32 hbgtwvg" + echo -n "$libs rddads hbct hbnf hbzlib hbtip xhb hbgd hbodbc hbpg hbmysql rddado hbw32 gtwvg" else echo -n "$@" fi @@ -424,7 +424,7 @@ else fi [ "\${HB_MT}" = "MT" ] && [ -f "\${HB_LIB_INSTALL}/\${pref}\${l}mt\${ext}" ] && l="\${l}mt" [ -f "\${HB_LIB_INSTALL}/\${pref}\${l}\${ext}" ] && HARBOUR_LIBS="\${HARBOUR_LIBS} -l\${l}" - libs="gtalleg debug profiler ${hb_libsc}" + libs="gtalleg hbdebug profiler ${hb_libsc}" fi for l in \${libs} do @@ -603,7 +603,7 @@ mk_hblibso() for l in ${hb_libs} do case $l in - debug|profiler|fm|hbodbc|gtalleg|hbrddads) ;; + hbdebug|profiler|fm|hbodbc|gtalleg|rddads) ;; *) ls="lib${l}.a" if [ -f lib${l}mt.a ] diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 9b32ff6c75..50e9d6b001 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -998,6 +998,8 @@ extern HB_EXPORT BOOL hb_printerIsReady( char * pszPrinterName ); /* environment variables access */ /* WARNING: This returned pointer must be freed if not NULL using hb_xfree( ( void * ) ptr ); */ extern char * hb_getenv( const char * name ); +extern char * hb_netname( void ); +extern char * hb_username( void ); /* Version tracking related things */ #ifdef HB_FILE_VER_STATIC diff --git a/harbour/source/rtl/net.c b/harbour/source/rtl/net.c index 7a40fe8233..54536782a8 100644 --- a/harbour/source/rtl/net.c +++ b/harbour/source/rtl/net.c @@ -101,50 +101,49 @@ #endif /* NOTE: Clipper will only return a maximum of 15 bytes from this function. - And it will be padded with spaces. Harbour does the same in the + And it will be padded with spaces. Harbour does the same on the DOS platform. [vszakats] */ -HB_FUNC( NETNAME ) +/* NOTE: The caller must free the returned buffer. [vszakats] */ + +char * hb_netname( void ) { #if defined(HB_OS_UNIX) || ( defined(HB_OS_OS2) && defined(__GNUC__) ) # if defined(__WATCOMC__) - char * pszValue = hb_getenv( "HOSTNAME" ); - hb_retc_buffer( pszValue ); + return hb_getenv( "HOSTNAME" ); # else - char szValue[ MAXGETHOSTNAME + 1 ]; - szValue[ 0 ] = '\0'; - gethostname( szValue, MAXGETHOSTNAME ); - hb_retc( szValue ); + char * pszValue = hb_xgrab( MAXGETHOSTNAME + 1 ); + pszValue[ 0 ] = '\0'; + gethostname( pszValue, MAXGETHOSTNAME ); + return szValue; # endif #elif defined(HB_OS_DOS) # if defined(__DJGPP__) || defined(__RSX32__) || defined(__GNUC__) - char szValue[ MAXGETHOSTNAME + 1 ]; - szValue[ 0 ] = '\0'; - - gethostname( szValue, MAXGETHOSTNAME ); - - hb_retc( szValue ); + char * pszValue = hb_xgrab( MAXGETHOSTNAME + 1 ); + pszValue[ 0 ] = '\0'; + gethostname( pszValue, MAXGETHOSTNAME ); + return szValue; # else union REGS regs; - char szValue[ 16 ]; - szValue[ 0 ] = '\0'; + char * pszValue = hb_xgrab( 16 ); + pszValue[ 0 ] = '\0'; regs.HB_XREGS.ax = 0x5E00; { struct SREGS sregs; - regs.HB_XREGS.dx = FP_OFF( szValue ); - sregs.ds = FP_SEG( szValue ); + regs.HB_XREGS.dx = FP_OFF( pszValue ); + sregs.ds = FP_SEG( pszValue ); HB_DOS_INT86X( 0x21, ®s, ®s, &sregs ); } - hb_retc( regs.h.ch == 0 ? "" : szValue ); + return regs.h.ch == 0 ? "" : pszValue; # endif #elif defined(HB_OS_WIN_32) @@ -154,29 +153,32 @@ HB_FUNC( NETNAME ) pszValue[ 0 ] = '\0'; GetComputerNameA( pszValue, &ulLen ); - hb_retc_buffer( pszValue ); + return pszValue; #else - hb_retc( NULL ); + return NULL; #endif } -HB_FUNC( HB_USERNAME ) +/* NOTE: The caller must free the returned buffer. [vszakats] */ + +char * hb_username( void ) { #if defined(HB_OS_UNIX) || ( defined(HB_OS_OS2) && defined(__GNUC__) ) # if defined(__WATCOMC__) - char * pszValue = hb_getenv( "USER" ); - hb_retc_buffer( pszValue ); + return hb_getenv( "USER" ); # else struct passwd * pwd; pwd = getpwuid( getuid() ); if( pwd ) - hb_retc( pwd->pw_name ); + { + return hb_strdup( pwd->pw_name ); + } else - hb_retc_buffer( hb_getenv( "USER" ) ); + return hb_getenv( "USER" ); # endif #elif defined(HB_OS_WIN_32) @@ -186,11 +188,21 @@ HB_FUNC( HB_USERNAME ) pszValue[ 0 ] = '\0'; GetUserNameA( pszValue, &ulLen ); - hb_retc_buffer( pszValue ); + return pszValue; #else - hb_retc( NULL ); + return NULL; #endif } + +HB_FUNC( NETNAME ) +{ + hb_retc_buffer( hb_netname() ); +} + +HB_FUNC( HB_USERNAME ) +{ + hb_retc_buffer( hb_username() ); +}