EnglishРусский  

   ..

   defines.c

   defines.h

   ini.c

   ini.h

The project is closed! You can look at a new scripting language. It is available on GitHub.
Also, try our open source cross-platform automation software.

Ads

Installer and installation software
Commercial and Freeware installers.

source\src\os\linux\defines.c
   1 /******************************************************************************
   2 *
   3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
   4 * This file is part of the Gentee open source project - http://www.gentee.com.
   5 *
   6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
   7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
   8 * ACCEPTANCE OF THE AGREEMENT.
   9 *
  10 * ID: defines 18.10.06 0.0.A.
  11 *
  12 * Author: Alexey Krivonogov
  13 *
  14 * Summary: This file provides Windows basic types and some constants.
  15 *
  16 ******************************************************************************/
  17 
  18 #include "defines.h"
  19 #include "../../genteeapi/gentee.h"
  20 #ifdef LINUX
  21    #include <unistd.h>
  22    #include <fcntl.h>
  23    #include <stdarg.h>
  24    #include <sys/types.h>
  25    #include <sys/stat.h>
  26    #include <sys/times.h>
  27    #include <dirent.h>
  28    #include <pthread.h>
  29    #include <stdio.h>
  30    //#include <wvstreams/wvstrutils.h>
  31    #include <string.h>
  32    #include <errno.h>
  33 #else
  34    #include "shlobj.h"
  35 #endif
  36 
  37 #ifdef WINDOWS
  38  pvoid  _stdout = INVALID_HANDLE_VALUE;
  39  pvoid  _stdin = INVALID_HANDLE_VALUE;
  40 #endif
  41 
  42 /*-----------------------------------------------------------------------------
  43 *
  44 * ID: os_dircreate 14.12.07
  45 *
  46 * Summary: Create the directory
  47 *
  48 -----------------------------------------------------------------------------*/
  49 
  50 uint     STDCALL os_dircreate( pstr name )
  51 {
  52  #ifdef LINUX
  53    return mkdir(str_ptr( name ),700);
  54  #else
  55    return CreateDirectory( str_ptr( name ), NULL );
  56  #endif
  57 }
  58 
  59 /*-----------------------------------------------------------------------------
  60 *
  61 * ID: os_dirdelete 14.12.07
  62 *
  63 * Summary: Delete the empty directory
  64 *
  65 -----------------------------------------------------------------------------*/
  66 
  67 uint     STDCALL os_dirdelete( pstr name )
  68 {
  69   #ifdef LINUX
  70    return rmdir(str_ptr( name ));
  71   #else
  72    return RemoveDirectory( str_ptr( name ));
  73   #endif
  74 }
  75 
  76 /*-----------------------------------------------------------------------------
  77 *
  78 * ID: os_dirgetcur 14.12.07
  79 *
  80 * Summary: Get the current directory
  81 *
  82 -----------------------------------------------------------------------------*/
  83 
  84 pstr   STDCALL os_dirgetcur( pstr name )
  85 {
  86    #ifdef LINUX
  87     return str_setlen( name,getcwd( str_ptr( name), 512 ));
  88    #else
  89     return str_setlen( name, GetCurrentDirectory( 512,str_ptr( str_reserve( name, 512 ))));
  90    #endif
  91 }
  92 
  93 /*-----------------------------------------------------------------------------
  94 *
  95 * ID: os_dirsetcur 14.12.07
  96 *
  97 * Summary: Set the current directory
  98 *
  99 -----------------------------------------------------------------------------*/
 100 
 101 uint  STDCALL os_dirsetcur( pstr name )
 102 {
 103    #ifdef LINUX
 104     return chdir( str_ptr( name));
 105    #else
 106     return SetCurrentDirectory( str_ptr( name ));
 107    #endif
 108 }
 109 
 110 /*-----------------------------------------------------------------------------
 111 *
 112 * ID: os_dirdeletefull 14.12.07
 113 *
 114 * Summary: Delete the directory with subfolders and files
 115 *
 116 -----------------------------------------------------------------------------*/
 117 
 118 uint     STDCALL os_dirdeletefull( pstr name )
 119 {
 120  #ifdef WINDOWS
 121    str  stemp;
 122    WIN32_FIND_DATA  data;
 123    pvoid            find;
 124 
 125    str_init( &stemp );
 126    str_printf( &stemp, "%s%c*.*", str_ptr( name ), SLASH );
 127    find = FindFirstFile( str_ptr( &stemp ), &data );
 128    if ( find != INVALID_HANDLE_VALUE )
 129    {
 130       do {
 131          if ( data.cFileName[0] == '.' && ( !data.cFileName[1] ||
 132             ( data.cFileName[1] == '.' && !data.cFileName[2] )))
 133             continue;
 134 
 135          str_printf( &stemp, "%s%c%s", str_ptr( name ), SLASH, data.cFileName );
 136 
 137          if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
 138             os_dirdeletefull( &stemp );
 139          else
 140             os_filedelete( &stemp );
 141 
 142       } while ( FindNextFile( find, &data ));
 143 
 144       FindClose( find );
 145    }
 146    str_delete( &stemp );
 147  #endif
 148    return os_dirdelete( name );
 149 }
 150 
 151 /*-----------------------------------------------------------------------------
 152 *
 153 * ID: os_fileclose 14.12.07
 154 *
 155 * Summary: Close the file
 156 *
 157 -----------------------------------------------------------------------------*/
 158 
 159 uint     STDCALL os_fileclose( uint handle )
 160 {
 161   #ifdef LINUX
 162    return close((handle ));
 163   #else
 164    return CloseHandle(( pvoid )handle );
 165   #endif
 166 }
 167 
 168 /*-----------------------------------------------------------------------------
 169 *
 170 * ID: os_filefullname 14.12.07
 171 *
 172 * Summary: Get the full name of the file
 173 *
 174 -----------------------------------------------------------------------------*/
 175 /*
 176 pstr  STDCALL os_filefullname( pstr filename, pstr result )
 177 {
 178 
 179    str_reserve( result, 512 );
 180    //if ( ichar != SLASH )
 181    //printf("ddddddddddd");
 182     //result = "DEMO";
 183     //str_copy(result, "DEMO");
 184     //return result;
 185    //if ( str_findch(filename,SLASH) != 0 )
 186    pubyte dddd = (pubyte)filename;
 187    if ( dddd[0] == '/' )
 188    {
 189       char  cur[512];
 190       getcwd( cur, 512 );
 191       chdir( filename );
 192       basename( filename );
 193       getcwd( str_ptr( result ), 512 );
 194       uint iDov = str_len( result );
 195       //str_setlen(result, strlen( str_ptr( result ) ) );
 196       str_setlen(result, strlen( (pubyte) result ) );
 197       str_add( result, "/" );
 198       str_add( result, filename );
 199       chdir( cur );
 200    }
 201    else
 202    { //Œ®¦¥â à ¡®â âì ­¥ª®à४⭮ ¥á«¨ ¢  ¡á®«îâ­®¬ ¯ã⨠¢áâà¥ç îâáï '.' '..'
 203       str_copy( result, filename );
 204    }
 205    return result;
 206 
 207 }
 208 */
 209 
 210 pvoid  STDCALL os_filefullname( pubyte filename, pvoid buf )
 211 {
 212    pubyte  ptr;
 213 
 214 #ifdef LINUX
 215 
 216    char  cur[512];
 217    if ( filename[0] != '/' )
 218    {
 219       getcwd( cur, 512 );
 220       chdir( filename );
 221       basename( filename );
 222       getcwd( str_ptr( ( pstr )buf ), 512 );
 223       str_setlen( ( pstr )buf, strlen( str_ptr( ( pstr )buf ) ) );
 224       str_appendb( buf, '/' );
 225        str_appendp( buf, filename );
 226       chdir( cur );
 227    }
 228    else
 229    { //Ìîæåò ðàáîòàòü íåêîððåêòíî åñëè â àáñîëþòíîì ïóòè âñòðå÷àþòñÿ '.' '..'
 230        str_appendp( buf, filename );
 231    }
 232 #else
 233    DWORD  temp;
 234    temp = GetFullPathName( filename, 512, str_ptr( ( pstr )buf ), &ptr );
 235    // äëÿ Windows
 236    CharLowerBuff( str_ptr( ( pstr )buf ), temp );
 237    str_setlen( ( pstr )buf, temp );
 238 #endif
 239    return buf;
 240 }
 241 
 242 
 243 
 244 /*-----------------------------------------------------------------------------
 245 *
 246 * ID: os_filedelete 14.12.07 .
 247 *
 248 * Summary: Delete the file
 249 *
 250 -----------------------------------------------------------------------------*/
 251 
 252 uint     STDCALL os_filedelete( pstr name )
 253 {
 254     #ifdef LINUX
 255      return remove(str_ptr(name));
 256     #else
 257      return DeleteFile( str_ptr( name ));
 258     #endif
 259 }
 260 
 261 uint  STDCALL os_fileopen( pstr name, uint flag )
 262 {
 263 #ifdef LINUX
 264    int fd;
 265    fd = open( name, ( flag & FOP_READONLY ? O_RDONLY : O_RDWR ) |
 266                     ( flag & FOP_CREATE ? O_CREAT : 0 ) |
 267                     ( flag & FOP_IFCREATE ? O_TRUNC : 0 ), S_IRWXU );
 268    if ( fd != -1 && flag & FOP_EXCLUSIVE )
 269    {
 270       if ( flock( fd, LOCK_EX ) == -1 )
 271       {
 272         	close( fd );
 273 			fd = -1;
 274       }
 275    }
 276    return fd;
 277 #else
 278    uint ret;
 279 
 280    ret = ( uint )CreateFile( str_ptr( name ), ( flag & FOP_READONLY ? GENERIC_READ :
 281             GENERIC_READ | GENERIC_WRITE ), ( flag & FOP_EXCLUSIVE ? 0 :
 282             FILE_SHARE_READ | FILE_SHARE_WRITE ), NULL,
 283            ( flag & FOP_CREATE ? CREATE_ALWAYS :
 284               ( flag & FOP_IFCREATE ? OPEN_ALWAYS : OPEN_EXISTING )),
 285            /*FILE_FLAG_WRITE_THROUGH*/ 0, NULL );
 286    //printf("Name=%s %i\n", str_ptr( name ), ret );
 287    return ret == ( uint )INVALID_HANDLE_VALUE ? 0 : ret ;
 288 #endif
 289 
 290 }
 291 
 292 ulong64  STDCALL os_filepos( uint handle, long64 offset, uint mode )
 293 {
 294 
 295   #ifdef LINUX
 296    int newset;
 297    newset = lseek( handle, offset, ( mode == FSET_BEGIN ?
 298       SEEK_SET : ( mode == FSET_CURRENT ? SEEK_CUR : SEEK_END )));
 299    if ( newset == offset - 1 )
 300       return -1;
 301    return newset;
 302   #else
 303    LARGE_INTEGER  li;
 304 
 305    li.QuadPart = offset;
 306 
 307    li.LowPart = SetFilePointer( ( pvoid )handle, li.LowPart, &li.HighPart,
 308        ( mode == FSET_BEGIN ?
 309       FILE_BEGIN : ( mode == FSET_CURRENT ? FILE_CURRENT : FILE_END )));
 310    if ( li.LowPart == MAX_UINT && GetLastError() != NO_ERROR )
 311       return -1L;
 312    return li.QuadPart;
 313   #endif
 314 }
 315 
 316 uint   STDCALL os_fileread( uint handle, pubyte data, uint size )
 317 {
 318   #ifdef LINUX
 319    uint  cntread;
 320    cntread = read( handle, data, size );
 321    if ( cntread == -1 || cntread != size )
 322       return FALSE;
 323    return TRUE;
 324   #else
 325    uint  read;
 326    if ( !ReadFile( (pvoid)handle, data, size, &read, NULL ) || read != size )
 327       return FALSE;
 328    return read;
 329   #endif
 330 }
 331 
 332 ulong64  STDCALL os_filesize( uint handle )
 333 {
 334   #ifdef LINUX
 335    long size, curoff;
 336    curoff = lseek( handle, 0, SEEK_CUR );
 337    size = lseek( handle, 0, SEEK_END );
 338    lseek( handle, curoff, SEEK_SET );
 339    return size;
 340   #else
 341    LARGE_INTEGER  li;
 342    li.LowPart = GetFileSize( ( pvoid )handle, &li.HighPart );
 343    if ( li.LowPart == INVALID_FILE_SIZE && GetLastError() != NO_ERROR )
 344       return -1L;
 345    return li.QuadPart;
 346   #endif
 347 }
 348 
 349 //--------------------------------------------------------------------------
 350 
 351 uint   STDCALL os_filewrite( uint handle, pubyte data, uint size )
 352 {
 353   #ifdef LINUX
 354    uint  cntwrite;
 355    cntwrite = write( handle, data, size );
 356    if ( cntwrite == -1 || cntwrite != size )
 357       return FALSE;
 358    return TRUE;
 359   #else
 360    uint  write;
 361    if ( !WriteFile( ( pvoid )handle, data, size, &write, NULL ) || write != size )
 362       return FALSE;
 363    return write;
 364   #endif
 365 }
 366 
 367 /*-----------------------------------------------------------------------------
 368 *
 369 * ID: os_fileexist 14.12.07 .
 370 *
 371 * Summary: If the file or directory exists
 372 *
 373 -----------------------------------------------------------------------------*/
 374 
 375 uint STDCALL os_fileexist( pstr name )
 376 {
 377    return os_getattrib( name ) != 0xFFFFFFFF ? 1 : 0;
 378 }
 379 
 380 /*-----------------------------------------------------------------------------
 381 *
 382 * ID: os_getattrib 14.12.07 .
 383 *
 384 * Summary: Get the file or directory attrbutes
 385 *
 386 -----------------------------------------------------------------------------*/
 387 
 388 uint  STDCALL os_getattrib( pstr name )
 389 {
 390     #ifdef LINUX
 391      struct stat statbuf;
 392      stat(str_ptr(name),&statbuf);
 393      return statbuf.st_mode;
 394     #else
 395          return GetFileAttributes( str_ptr( name ));
 396     #endif
 397 
 398 }
 399 
 400 /*-----------------------------------------------------------------------------
 401 *
 402 * ID: os_tempdir 14.12.07 .
 403 *
 404 * Summary: Get the temp dir
 405 *
 406 -----------------------------------------------------------------------------*/
 407 
 408 pstr  STDCALL os_tempdir( pstr name )
 409 {
 410   #ifdef LINUX
 411    pstr stemp = os_gettemp();
 412    uint uLenTempStr  =  str_len(stemp);
 413    str_copy(name,stemp);
 414   #else
 415    str_setlen( name, GetTempPath( 1024, str_reserve( name, 1024 )->data ));
 416   #endif
 417   return str_trim( name, SLASH, TRIM_ONE | TRIM_RIGHT );
 418 }
 419 
 420 pstr  STDCALL os_gettemp( void )
 421 {
 422    uint  diskc = 0;
 423    pstr  temp;
 424    pstr  ret;
 425 //   ubyte temp[ 512 ];
 426 //   ubyte stemp[ 512 ];
 427 
 428 //   str_lenset( dir, 0 );
 429 //   str_isfree( dir, 512 );
 430 /*#ifdef LINUX
 431    if ( !ggentee.tempfile )
 432    {
 433       while( 1 )
 434       {
 435          wsprintf( stemp, "/temp/gentee%02X.tmp", ggentee.tempid );
 436          ggentee.tempfile = file_open( stemp, FOP_CREATE | FOP_EXCLUSIVE );
 437          if ( ggentee.tempfile = -1 )
 438             ggentee.tempid++;
 439          else
 440             break;
 441       }
 442       stemp[ mem_len( stemp ) - 4 ] = 0;
 443 //      wsprintf( stemp, "%s\\gentee%02X", temp, ggentee.tempid );
 444       mkdir( stemp, 700 );
 445       ggentee.tempdir = str_new( 0, stemp );
 446    }
 447 //   str_appendp( dir, str_ptr( ggentee.tempdir ));
 448 #else*/
 449    if ( !_gentee.tempfile )
 450    {
 451       temp = str_new( NULL );
 452       ret = str_new( NULL );
 453       os_tempdir( temp );
 454 
 455       while ( 1 )
 456       {
 457          str_clear( ret );
 458          str_printf( ret, "%s\\gentee%02X.tmp", str_ptr( temp ), _gentee.tempid );
 459 
 460          _gentee.tempfile = os_fileopen( ret, FOP_CREATE | FOP_EXCLUSIVE );
 461 
 462          if ( !_gentee.tempfile )
 463          {
 464             if ( os_getattrib( ret ) == 0xFFFFFFFF )
 465                if ( !diskc )
 466                {
 467                   str_copyzero( temp, "c:\\temp" );
 468                   os_dircreate( temp );
 469                   diskc = 1;
 470                }
 471                else
 472                   msg( MFileopen | MSG_STR, ret );
 473             _gentee.tempid++;
 474          }
 475          else
 476             break;
 477       }
 478       str_setlen( ret, str_len( ret ) - 4 );
 479       os_dircreate( ret );
 480       str_copy( &_gentee.tempdir, ret );
 481 
 482       str_destroy( temp );
 483       str_destroy( ret );
 484    }
 485 //#endif
 486    return &_gentee.tempdir;
 487 }
 488 
 489 /*-----------------------------------------------------------------------------
 490 *
 491 * ID: os_init 14.12.07 .
 492 *
 493 * Summary: Initializing input and output.
 494 *
 495 -----------------------------------------------------------------------------*/
 496 
 497 void   STDCALL os_init( uint param )
 498 {
 499  #ifdef LINUX
 500   _gentee.multib = 0;
 501  #else
 502    if ( param )  // if ( !GetConsoleWindow( ))
 503       AllocConsole();
 504    else
 505    {
 506       CPINFO cpinfo;
 507 
 508       GetCPInfo( CP_ACP, &cpinfo );
 509       _gentee.multib = cpinfo.MaxCharSize > 1 ? 1 : 0;
 510    }
 511    if ( _gentee.flags & G_CONSOLE || param )
 512    {
 513       _stdout = GetStdHandle( STD_OUTPUT_HANDLE );
 514       _stdin = GetStdHandle( STD_INPUT_HANDLE );
 515    }
 516  #endif
 517 }
 518 
 519 /*-----------------------------------------------------------------------------
 520 *
 521 * ID: os_print 14.12.07 .
 522 *
 523 * Summary: Print a text to the console.
 524 *
 525 -----------------------------------------------------------------------------*/
 526 
 527 void   STDCALL os_print( pubyte ptr, uint len )
 528 {
 529    //if (_gentee.print) :  _gentee.print(ptr,len);
 530 
 531   #ifdef LINUX
 532     write(1,ptr,len);
 533   #else
 534    uint    write;
 535    pubyte  charprn;
 536 
 537    if ( _gentee.flags & G_CHARPRN )
 538    {
 539       charprn = ( pubyte )mem_alloc( len + 1 );
 540       //CharToOem( ptr, charprn );
 541       ptr = charprn;
 542    }
 543    if ( _gentee.flags & G_CONSOLE )
 544       //WriteFile( _stdout, ptr, len, &write, 0 );
 545       os_filewrite( _stdout , ptr, len);
 546    else
 547    {
 548       if ( _stdout == INVALID_HANDLE_VALUE )
 549           os_init( 1 );
 550       //WriteConsole( _stdout, ptr, len, &write, NULL );
 551    }
 552    if ( _gentee.flags & G_CHARPRN )
 553       mem_free( charprn );
 554   #endif
 555 
 556 }
 557 
 558 /*-----------------------------------------------------------------------------
 559 *
 560 * ID: os_getch 14.12.07 .
 561 *
 562 * Summary: Get a character form the console.
 563 *
 564 -----------------------------------------------------------------------------*/
 565 
 566 uint    STDCALL os_getchar( void )
 567 {
 568   #ifdef LINUX
 569    return getchar();
 570   #else
 571    uint  mode, get;
 572    ubyte input[8];
 573 
 574    if(_gentee.getch)
 575      return _gentee.getch(0,1);
 576 
 577    if ( _stdin == INVALID_HANDLE_VALUE )
 578       os_init( 1 );
 579 
 580    GetConsoleMode( _stdin, &mode );
 581    SetConsoleMode( _stdin, 0 );
 582    ReadConsole( _stdin, input, 1, &get, NULL );
 583    SetConsoleMode( _stdin, mode );
 584 //   return _getch();
 585    return input[0];
 586   #endif
 587 }
 588 
 589 /*-----------------------------------------------------------------------------
 590 *
 591 * ID: os_scan 14.12.07 .
 592 *
 593 * Summary: Get characters form the console.
 594 *
 595 -----------------------------------------------------------------------------*/
 596 
 597 uint  STDCALL os_scan( pubyte input, uint len )
 598 {
 599 
 600   #ifdef LINUX
 601    return read(0,input,len);
 602   #else
 603    uint   read;
 604 
 605    if (_gentee.getch)
 606     return _gentee.getch(input,len);
 607 
 608    if ( _stdin == INVALID_HANDLE_VALUE )
 609       os_init( 1 );
 610    ReadConsole( _stdin, input, len, &read, NULL );
 611 
 612    return read;
 613   #endif
 614 }
 615 
 616 /*-----------------------------------------------------------------------------
 617 *
 618 * ID: os_strcmplen 14.12.07 .
 619 *
 620 * Summary: Compare strings
 621 *
 622 -----------------------------------------------------------------------------*/
 623 
 624 int   STDCALL os_strcmplen( pubyte one, pubyte two, uint len )
 625 {
 626  #ifdef LINUX
 627   int cmp = strcmp(one,two);
 628   if (cmp < 0)
 629    return -1;
 630   if (cmp > 0)
 631    return 1;
 632  #else
 633    int cmp = CompareString( LOCALE_USER_DEFAULT, 0, one, len, two, len );
 634    if ( cmp == CSTR_LESS_THAN )
 635       return -1;
 636    if ( cmp == CSTR_GREATER_THAN )
 637       return 1;
 638  #endif
 639    return 0;
 640 }
 641 
 642 /*-----------------------------------------------------------------------------
 643 *
 644 * ID: os_strcmpignlen 14.12.07 .
 645 *
 646 * Summary: Compare strings
 647 *
 648 -----------------------------------------------------------------------------*/
 649 
 650 int   STDCALL os_strcmpignlen( pubyte one, pubyte two, uint len )
 651 {
 652   #ifdef LINUX
 653   int cmp = strncasecmp(one,two,len);
 654   if (cmp < 0)
 655    return -1;
 656   if (cmp > 0)
 657    return 1;
 658   #else
 659    int cmp = CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE, one, len, two, len );
 660 
 661    if ( cmp == CSTR_LESS_THAN )
 662       return -1;
 663    if ( cmp == CSTR_GREATER_THAN )
 664       return 1;
 665   #endif
 666    return 0;
 667 }
 668 
 669 /*-----------------------------------------------------------------------------
 670 *
 671 * ID: os_ustrcmplen 14.12.07 .
 672 *
 673 * Summary: Compare strings
 674 *
 675 -----------------------------------------------------------------------------*/
 676 
 677 int   STDCALL os_ustrcmplen( pushort one, pushort two, uint len )
 678 {
 679  #ifdef LINUX
 680   int cmp = strncmp(one,two,len);
 681   if (cmp < 0)
 682    return -1;
 683   if (cmp > 0)
 684    return 1;
 685  #else
 686    int cmp = CompareStringW( LOCALE_USER_DEFAULT, 0, one, len, two, len );
 687    if ( cmp == CSTR_LESS_THAN )
 688       return -1;
 689    if ( cmp == CSTR_GREATER_THAN )
 690       return 1;
 691  #endif
 692    return 0;
 693 }
 694 
 695 /*-----------------------------------------------------------------------------
 696 *
 697 * ID: os_strcmpignlen 14.12.07 .
 698 *
 699 * Summary: Compare strings
 700 *
 701 -----------------------------------------------------------------------------*/
 702 
 703 int   STDCALL os_ustrcmpignlen( pushort one, pushort two, uint len )
 704 {
 705   #ifdef WINDOWS
 706    int cmp = CompareStringW( LOCALE_USER_DEFAULT, NORM_IGNORECASE, one, len, two, len );
 707 
 708    if ( cmp == CSTR_LESS_THAN )
 709       return -1;
 710    if ( cmp == CSTR_GREATER_THAN )
 711       return 1;
 712   #endif
 713    return 0;
 714 }
 715 
 716 /*-----------------------------------------------------------------------------
 717 *
 718 * ID: os_strcmp 14.12.07 .
 719 *
 720 * Summary: Compare strings
 721 *
 722 -----------------------------------------------------------------------------*/
 723 
 724 int   STDCALL os_strcmp( pubyte one, pubyte two )
 725 {
 726    return os_strcmplen( one, two, -1 );
 727 }
 728 
 729 /*-----------------------------------------------------------------------------
 730 *
 731 * ID: os_strcmpign 14.12.07 .
 732 *
 733 * Summary: Compare strings
 734 *
 735 -----------------------------------------------------------------------------*/
 736 
 737 int   STDCALL os_strcmpign( pubyte one, pubyte two )
 738 {
 739    return os_strcmpignlen( one, two, -1 );
 740 }
 741 
 742 /*-----------------------------------------------------------------------------
 743 *
 744 * ID: os_strcmp 14.12.07 .
 745 *
 746 * Summary: Compare strings
 747 *
 748 -----------------------------------------------------------------------------*/
 749 
 750 int   STDCALL os_ustrcmp( pushort one, pushort two )
 751 {
 752    return os_ustrcmplen( one, two, -1 );
 753 }
 754 
 755 /*-----------------------------------------------------------------------------
 756 *
 757 * ID: os_strcmpign 14.12.07 .
 758 *
 759 * Summary: Compare strings
 760 *
 761 -----------------------------------------------------------------------------*/
 762 
 763 int   STDCALL os_ustrcmpign( pushort one, pushort two )
 764 {
 765    return os_ustrcmpignlen( one, two, -1 );
 766 }
 767 
 768 //--------------------------------------------------------------------------
 769 
 770 /*
 771 pvoid STDCALL os_alloc( uint size )
 772 {
 773    return VirtualAlloc( NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE );
 774 }
 775 
 776 void STDCALL os_free( pvoid ptr )
 777 {
 778    VirtualFree( ptr, 0, MEM_RELEASE );
 779 }
 780  */
 781 //--------------------------------------------------------------------------
 782 
 783 uint STDCALL os_time()
 784 {
 785     #ifdef LINUX
 786      struct tms tm1;
 787      return times(&tm1);
 788     #else
 789      return GetTickCount();
 790     #endif
 791 }
 792 
 793 pubyte STDCALL os_lower(pubyte pData)
 794 {
 795     #ifdef LINUX
 796      return strlower3(pData);
 797      //return strlower2(pData);
 798     #else
 799      return CharLower(pData);
 800     #endif
 801 }
 802 
 803 pubyte STDCALL strlower1(pubyte string1)
 804 {
 805     pubyte it = string1;
 806     if (string1)
 807     {
 808         while (*it != 0)
 809         {
 810             if (!isdigit(*it))
 811               *it = tolower(*it);
 812             ++it;
 813         }
 814 /*
 815         for (s=string1;*s;++s) {
 816            if (!isdigit(*s))
 817              *s=tolower(*s);
 818         }
 819     */
 820     }
 821     return string1;
 822 }
 823 
 824 pvoid STDCALL os_thread(pvoid pfunc,pvoid param)
 825 {
 826     uint id;
 827 
 828     #ifdef LINUX
 829       pthread_t thread_id;
 830       //uint thread_id;
 831       int rc;
 832       rc = pthread_create(&thread_id,NULL,pfunc,param);
 833       return (uint) thread_id;
 834     #else
 835       return CreateThread(0,0,pfunc,param,0,&id);
 836     #endif
 837 }
 838 
 839 pubyte   STDCALL os_getexepath( pubyte dir, pubyte name )
 840 {
 841    uint len;
 842    //ubyte ptr_Test[512];
 843   pstr sDir,sName;
 844 
 845 
 846 #ifdef LINUX
 847    //Only for linux
 848 //   dir[0] = 0;
 849 //   name[0] = 0;
 850    len = readlink( "/proc/self/exe", dir, 512 )- 1 ;
 851    while ( len && dir[ len ] != '/' ) {
 852         //dir[ len ] = ' ' ;
 853         len--;
 854    }
 855    mem_copyuntilzero( dir + len + 1, name );
 856 #else
 857    len = GetModuleFileName( 0, dir, 512 ) - 1;
 858    while ( len && dir[ len ] != '\\' ) len--;
 859    mem_copyuntilzero( dir + len + 1, name );
 860 #endif
 861    return dir;
 862 }
 863 
 864 #ifdef LINUX
 865 /*
 866 pubyte  STDCALL os_getexename( pubyte buf, uint size )
 867 {
 868    uint len,lich=0;
 869    ubyte linkname[64];
 870    ubyte link_name[512];
 871    pid_t pid;
 872    int ret;
 873    pid= getpid();
 874 
 875    if(snprintf(linkname,sizeof(linkname),"/proc/%i/exe",pid) , 0)
 876    {
 877        abort();
 878    }
 879    ret = readlink(linkname,link_name,size);
 880    if (ret == -1) return NULL;
 881    while ( ret && link_name[ ret ] != '/' ) {
 882         //dir[ len ] = ' ' ;
 883         lich++;
 884    }
 885    mem_copyuntilzero( buf, link_name+ret-lich );
 886    //mem_copy(buf,link_name,+(ret-lich));
 887    return buf;
 888 }
 889 */
 890 pubyte   STDCALL os_getexename( pubyte dir)
 891 {
 892    uint len,lich=0;
 893    ubyte dir2[512];
 894    //ubyte ptr_Test[512];
 895 
 896    len = readlink( "/proc/self/exe", dir2, 512 )- 1 ;
 897    while ( len && dir2[ len ] != '/' ) {
 898         //dir[ len ] = ' ' ;
 899         lich++;
 900         len--;
 901    }
 902    mem_copyuntilzero( dir, dir2 + len + 1 - lich);
 903    //print( "dir =%s\n", dir );
 904    return dir;
 905 }
 906 
 907 char * strlower2(char * cstr1)
 908 {
 909     char * it = cstr1;
 910     while (*it != 0)
 911     {
 912         if (!isdigit(*it))
 913           *it = tolower(*it);
 914         ++it;
 915     }
 916     return cstr1;
 917 }
 918 
 919 void strlower3(char * s)
 920 {
 921     uint ddd = strlen(s);
 922     while (*s)
 923     {
 924         if (!isdigit(*s))
 925           *s = tolower(*s);
 926         s++;
 927     }
 928 }
 929 
 930 
 931 void os_splitpath(const char *src, char *drive, char *path, char *file, char *ext)
 932 /*                             , FILE_MAX+1,  PATH_MAX+1, FILE_MAX+1, FILE_MAX+1
 933                                  drive    :  /path/       name.egon   .tar.gz    */
 934 {
 935 	int len=0;
 936 	const char *ref1;
 937 	if (*src!='/')
 938 	if ((ref1=strchr(src, ':')))
 939 	{
 940 		if (((ref1+1)==strchr(src, '/'))||(!ref1[1]))
 941 		while (src<=ref1)
 942 		{
 943 			if (drive)
 944 			{
 945 				len++;
 946 				if (len<=NAME_MAX)
 947 				{
 948 					*drive=*src;
 949 					drive++;
 950 				}
 951 			}
 952 			if (*src==':')
 953 			{
 954 				src++;
 955 				break;
 956 			}
 957 			src++;
 958 		}
 959 	}
 960 	len=0;
 961 	if ((ref1=rindex(src, '/')))
 962 	while (src<=ref1)
 963 	{
 964 		if (path)
 965 		{
 966 			len++;
 967 			if (len<=PATH_MAX)
 968 			{
 969 				*path=*src;
 970 				path++;
 971 			}
 972 		}
 973 		src++;
 974 	}
 975 	len=0;
 976 	if (!(ref1=rindex(src, '.')))
 977 		ref1=src+strlen(src);
 978 	while (/*(*src)*/(src<ref1))
 979 	{
 980 /*		if (!strchr(src+1, '.'))
 981 			break;*/
 982 		if (!strcasecmp(src, ".tar.gz")) /* I am a bad boy */
 983 			break;
 984 		if (!strcasecmp(src, ".tar.bz2")) /* very bad */
 985 			break;
 986 		if (!strcasecmp(src, ".tar.Z")) /* and this is creepy */
 987 			break;
 988 		if (file)
 989 		{
 990 			len++;
 991 			if (len<=NAME_MAX)
 992 			{
 993 				*file=*src;
 994 				file++;
 995 			}
 996 		}
 997 		src++;
 998 	}
 999 	len=0;
1000 	while (*src)
1001 	{
1002 		if (ext)
1003 		{
1004 			len++;
1005 			if (len<=NAME_MAX)
1006 			{
1007 				*ext=*src;
1008 				ext++;
1009 			}
1010 		}
1011 		src++;
1012 	}
1013 	if (drive)
1014 		*drive=0;
1015 	if (path)
1016 		*path=0;
1017 	if (file)
1018 		*file=0;
1019 	if (ext)
1020 		*ext=0;
1021 }
1022 
1023 #endif
1024 
1025 
1026 void STDCALL os_exitthread(long retcode)
1027 {
1028     #ifdef LINUX
1029      pthread_exit((void*)retcode);
1030     #else
1031      ExitThread(retcode);
1032     #endif
1033 
1034 }
1035 
1036 
1037 /*
1038 char * strlwr(char* string)
1039 {
1040     char * s;
1041 
1042     if (string)
1043     {
1044         for (s = string;*s;++s)
1045          *s = toupper(s*);
1046     }
1047     return string;
1048 }
1049 */
1050