diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5e237eaa32..c3f7c33234 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,25 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-21 10:44 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + + harbour/contrib/hbposix/hbposix.h + + added header file for POSIX function wrappers + + * harbour/contrib/hbposix/hbposix.hbp + + harbour/contrib/hbposix/posixerr.c + + added C functions to save/restore errno value + + added POSIX_ERRNO() PRG function + + + harbour/contrib/hbposix/guids.c + + added POSIX_[GS]ET[E][UG]ID() functions + + * harbour/contrib/hbposix/daemon.c + * use hbposix.h + * save errno + + * harbour/contrib/hbposix/hbposix.c + * use hbposix.h + 2011-01-21 09:59 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + contrib/hbposix/tests/testdmn.prg * contrib/hbposix/hbposix.hbp diff --git a/harbour/contrib/hbposix/daemon.c b/harbour/contrib/hbposix/daemon.c index b6bb64fb0a..db1f255342 100644 --- a/harbour/contrib/hbposix/daemon.c +++ b/harbour/contrib/hbposix/daemon.c @@ -32,14 +32,11 @@ * SUCH DAMAGE. */ -#include "hbapi.h" +#include "hbposix.h" #include "hbvm.h" -#include -#include - /* - * hb_posix_daemon( lNoChdir, lNoClose ) --> lResult + * hb_posix_daemon( [], [] ) --> */ HB_FUNC( HB_POSIX_DAEMON ) { @@ -48,6 +45,7 @@ HB_FUNC( HB_POSIX_DAEMON ) switch( fork() ) { case -1: + hb_posix_save_errno(); hb_retl( HB_FALSE ); return; case 0: @@ -59,6 +57,7 @@ HB_FUNC( HB_POSIX_DAEMON ) if( setsid() == -1 ) { + hb_posix_save_errno(); hb_retl( HB_FALSE ); return; } @@ -75,5 +74,7 @@ HB_FUNC( HB_POSIX_DAEMON ) ( void ) close( fd ); } + hb_posix_set_errno( 0 ); + hb_retl( HB_TRUE ); } diff --git a/harbour/contrib/hbposix/guids.c b/harbour/contrib/hbposix/guids.c new file mode 100644 index 0000000000..f26cc6eec4 --- /dev/null +++ b/harbour/contrib/hbposix/guids.c @@ -0,0 +1,105 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * POSIX function wrappers to get/set user and group IDs + * + * Copyright 2011 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbposix.h" + +HB_FUNC( POSIX_GETUID ) +{ + hb_ret_uid( getuid() ); +} + +HB_FUNC( POSIX_GETEUID ) +{ + hb_ret_uid( geteuid() ); +} + +HB_FUNC( POSIX_GETGID ) +{ + hb_ret_uid( getgid() ); +} + +HB_FUNC( POSIX_GETEGID ) +{ + hb_ret_uid( getegid() ); +} + +HB_FUNC( POSIX_SETUID ) +{ + if( HB_ISNUM( 1 ) ) + hb_posix_result( setuid( hb_par_uid( 1 ) ) ); + else + hb_posix_param_error(); +} + +HB_FUNC( POSIX_SETEUID ) +{ + if( HB_ISNUM( 1 ) ) + hb_posix_result( seteuid( hb_par_uid( 1 ) ) ); + else + hb_posix_param_error(); +} + +HB_FUNC( POSIX_SETGID ) +{ + if( HB_ISNUM( 1 ) ) + hb_posix_result( setgid( hb_par_uid( 1 ) ) ); + else + hb_posix_param_error(); +} + +HB_FUNC( POSIX_SETEGID ) +{ + if( HB_ISNUM( 1 ) ) + hb_posix_result( setegid( hb_par_uid( 1 ) ) ); + else + hb_posix_param_error(); +} diff --git a/harbour/contrib/hbposix/hbposix.c b/harbour/contrib/hbposix/hbposix.c index f2c92e94ab..87fa5b5bb8 100644 --- a/harbour/contrib/hbposix/hbposix.c +++ b/harbour/contrib/hbposix/hbposix.c @@ -50,12 +50,10 @@ * */ -#include "hbapi.h" - -#include -#include +#include "hbposix.h" HB_FUNC( POSIX_GETPID ) { hb_retnint( getpid() ); } + diff --git a/harbour/contrib/hbposix/hbposix.h b/harbour/contrib/hbposix/hbposix.h new file mode 100644 index 0000000000..3780e9b812 --- /dev/null +++ b/harbour/contrib/hbposix/hbposix.h @@ -0,0 +1,79 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code + * header file for POSIX function wrappers + * + * Copyright 2011 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#ifndef __HBPOSIX_H +#define __HBPOSIX_H + +#include "hbapi.h" + +#include +#include +#include +#include +#include + + +#define hb_par_uid( n ) ( ( uid_t ) hb_parnl( n ) ) +#define hb_ret_uid( n ) hb_retnint( n ) + +HB_EXTERN_BEGIN + +void hb_posix_param_error( void ); +void hb_posix_result( int iResult ); + +void hb_posix_save_errno( void ); +void hb_posix_set_errno( int iErrNo ); +int hb_posix_get_errno( void ); + +HB_EXTERN_END + +#endif /* __HBPOSIX_H */ diff --git a/harbour/contrib/hbposix/hbposix.hbp b/harbour/contrib/hbposix/hbposix.hbp index d354c9951f..5676dd7231 100644 --- a/harbour/contrib/hbposix/hbposix.hbp +++ b/harbour/contrib/hbposix/hbposix.hbp @@ -13,3 +13,5 @@ hbposix.c daemon.c +guids.c +posixerr.c diff --git a/harbour/contrib/hbposix/posixerr.c b/harbour/contrib/hbposix/posixerr.c new file mode 100644 index 0000000000..9112ed54f9 --- /dev/null +++ b/harbour/contrib/hbposix/posixerr.c @@ -0,0 +1,100 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code + * POSIX function errno handling + * + * Copyright 2011 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbposix.h" +#include "hbstack.h" +#include "hbapierr.h" + +typedef struct +{ + int iErrNo; +} HB_POSIXERRDATA, * PHB_POSIXERRDATA; + +static HB_TSD_NEW( s_posix_errno, sizeof( HB_POSIXERRDATA ), NULL, NULL ); + +#define HB_POSIX_ERRNO ( ( PHB_POSIXERRDATA ) hb_stackGetTSD( &s_posix_errno ) ) + +void hb_posix_save_errno( void ) +{ + HB_POSIX_ERRNO->iErrNo = errno; +} + +void hb_posix_set_errno( int iErrNo ) +{ + HB_POSIX_ERRNO->iErrNo = iErrNo; +} + +int hb_posix_get_errno( void ) +{ + return HB_POSIX_ERRNO->iErrNo; +} + +void hb_posix_param_error( void ) +{ + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +void hb_posix_result( int iResult ) +{ + if( iResult == -1 ) + hb_posix_save_errno(); + else + hb_posix_set_errno( 0 ); + + hb_retni( iResult ); +} + + +HB_FUNC( POSIX_ERRNO ) +{ + hb_retni( HB_POSIX_ERRNO->iErrNo ); +}