Changeset 71 for trunk/orca/unix/os.c

Show
Ignore:
Timestamp:
03/03/06 19:14:39 (3 years ago)
Author:
krobillard
Message:

Added make-dir native.
Minor cleanup in file.c.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/orca/unix/os.c

    r42 r71  
    2323#include <sys/time.h> 
    2424#include <sys/stat.h> 
     25#include <errno.h> 
    2526#include <dirent.h> 
    2627#include <unistd.h> 
     
    4041 
    4142 
     43/** 
     44  Returns -1 if not present. 
     45*/ 
     46int orFileSize( const char* path ) 
     47{ 
     48    struct stat buf; 
     49    if( stat( path, &buf ) == -1 ) 
     50        return -1; 
     51    return buf.st_size; 
     52} 
     53 
     54 
     55/** 
     56  Returns 1 if directory, 0 if file or -1 if error. 
     57*/ 
     58int orIsDir( const char* path ) 
     59{ 
     60    struct stat buf; 
     61    if( stat( path, &buf ) == -1 ) 
     62        return -1; 
     63    return S_ISDIR(buf.st_mode) ? 1 : 0; 
     64} 
     65 
     66 
     67/** 
     68  Returns 0 if result set to file modification time or -1 if error. 
     69*/ 
     70int orFileModified( const char* path, OValue* res ) 
     71{ 
     72    struct stat buf; 
     73    if( stat( path, &buf ) == -1 ) 
     74        return -1; 
     75 
     76    orSetTF( res, OT_TIME ); 
     77    res->time.sec  = buf.st_mtime; 
     78    res->time.usec = 0; 
     79    return 0; 
     80} 
     81 
     82 
    4283/* 
    4384   change-dir 
     
    4687{ 
    4788    int logic = 0; 
    48     OString* str = orSTRINGS + a1->index; 
     89    OString* str = orSTRING(a1); 
     90    orTermCStr(str); 
    4991    if( chdir( str->charArray ) == 0 ) 
    5092        logic = 1; 
     
    69111            str->used = len; 
    70112            memCpy( str->charArray, orTmp, len ); 
    71             orResultFILE( str - orSTRINGS ); 
     113            orResultFILE( orStringN(str) ); 
    72114            return; 
    73115        } 
     
    78120 
    79121/** 
    80   Returns -1 if not present. 
    81 */ 
    82 int orFileSize( const char* path ) 
    83 { 
    84     struct stat buf; 
    85     if( stat( path, &buf ) == -1 ) 
    86         return -1; 
    87     return buf.st_size; 
    88 } 
    89  
    90  
    91 /** 
    92   Returns 1 if directory, 0 if file or -1 if error. 
    93 */ 
    94 int orIsDir( const char* path ) 
    95 { 
    96     struct stat buf; 
    97     if( stat( path, &buf ) == -1 ) 
    98         return -1; 
    99     return S_ISDIR(buf.st_mode) ? 1 : 0; 
    100 } 
    101  
    102  
    103 /** 
    104   Returns 0 if result set to file modification time or -1 if error. 
    105 */ 
    106 int orFileModified( const char* path, OValue* res ) 
    107 { 
    108     struct stat buf; 
    109     if( stat( path, &buf ) == -1 ) 
    110         return -1; 
    111  
    112     orSetTF( res, OT_TIME ); 
    113     res->time.sec  = buf.st_mtime; 
    114     res->time.usec = 0; 
    115     return 0; 
     122  No error if directory exists. 
     123*/ 
     124void orMakeDirNative( OValue* a1 ) 
     125{ 
     126    int err; 
     127    OString* str = orSTRING(a1); 
     128    orTermCStr(str); 
     129    err = mkdir( str->charArray, 0755 ); 
     130    if( err ) 
     131    { 
     132        if( (errno != EEXIST) || (orIsDir(str->charArray) != 1) ) 
     133        { 
     134            orErrorT( OR_ERROR_ACCESS, strerror/*_r*/(errno) ); 
     135        } 
     136    } 
    116137} 
    117138 
     
    229250        // What is the overhead of creating the arg list between fork/exec? 
    230251        char* argv[10]; 
    231         argumentList( orSTRINGS + a1->index, a1->series.it, argv, 9 ); 
     252        argumentList( orSTRING(a1), a1->series.it, argv, 9 ); 
    232253 
    233254        close( pfd[0] ); 
     
    306327        // What is the overhead of creating the arg list between fork/exec? 
    307328        char* argv[10]; 
    308         argumentList( orSTRINGS + a1->index, a1->series.it, argv, 9 ); 
     329        argumentList( orSTRING(a1), a1->series.it, argv, 9 ); 
    309330 
    310331        if( execvp( argv[0], argv ) == -1 )