Skip to content

Commit

Permalink
changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
guberathome committed Jan 7, 2025
1 parent 1d3e5e4 commit 82b212b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions examples/custom/01-parameter-passing/cf_demo1.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ static cell_t f4711( cell_t Val )
}

static cell_t FileInfo( cell_t path_caddr, cell_t path_len ) {
char* path = to_C_string( path_caddr, path_len );
struct stat info;
const char* fmtErr = "error{ id=%i, desc='%s', path='%s' }";
const char* fmtDir = "directory{ path='%s' }";
const char* fmtFile = "file{ size=%i, path='%s' }";
char* result;
/* MSYS/Cygwin may warn than asprintf() is not defined but compile and run just fine :-/ */
if( stat(path, &info) == -1 )
asprintf( &result, fmtErr, errno, strerror(errno), path );
else {
if( S_ISDIR(info.st_mode) )
asprintf( &result, fmtDir, path );
else
asprintf( &result, fmtFile, info.st_size, path );
}
char* path = to_C_string( path_caddr, path_len );
struct stat info;
const char* fmtErr = "error{ id=%i, desc='%s', path='%s' }";
const char* fmtDir = "directory{ path='%s' }";
const char* fmtFile = "file{ size=%i, path='%s' }";
char* result;
/* MSYS/Cygwin may warn than asprintf() is not defined but compile and run just fine :-/ */
if( stat(path, &info) == -1 )
asprintf( &result, fmtErr, errno, strerror(errno), path );
else {
if( S_ISDIR(info.st_mode) )
asprintf( &result, fmtDir, path );
else
asprintf( &result, fmtFile, info.st_size, path );
}
PUSH_DATA_STACK( (cell_t) result );
return (cell_t)strlen(result);
return (cell_t)strlen(result);
}


Expand Down
2 changes: 1 addition & 1 deletion examples/custom/01-parameter-passing/demo.fth
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
1000 f4711 . ." )"
CR

\ example of passing passing strings from PForth to custom C code
\ example of passing strings from PForth to custom C code
: SHOW-FILE-INFO
." " FILE-INFO type cr
;
Expand Down
2 changes: 1 addition & 1 deletion examples/custom/cf_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ static char* to_C_string( cell_t strData, cell_t iStrLen )
return buf;
}

#endif /* CF_HELPERS_H */
#endif /* CF_HELPERS_H */

0 comments on commit 82b212b

Please sign in to comment.