Hi Alex,

>> Alex, I need to call 'lseek' function.  How could I get hold of the
>> current input and output file descriptors?  I want to feed it to the
>
> Yep, implementing 'ifd' and 'ofd' (analog to 'ipid' and 'opid') would be
> the right way.

do you think it would be possible to include the following code in the
standard release?

#include <sys/types.h>
#include <unistd.h>

// (fpos 'fd) -> cnt
// (fpos 'fd 'off) -> cnt
// (fpos 'fd 'off 'flg) -> cnt
any fpos(any ex) {
   int fd = evCnt(ex, cdr(ex));
   off_t off = 0;
   int whence = SEEK_CUR;
   if(!isNil(cddr(ex))) {
      off = evCnt(ex, cddr(ex));
      if(!isNil(cdddr(ex))) {
         any w = evExpr(ex, cdddr(ex));
         whence = isNil(w) ? SEEK_SET : SEEK_END;
      }
   }
   off_t z = lseek(fd, off, whence);
   return boxCnt(z);
}

// (idf) -> cnt
any ifd(any ex __attribute__((unused))) {
   return boxCnt(InFile->fd);
}

// (odf) -> cnt
any ofd(any ex __attribute__((unused))) {
   return boxCnt(OutFile->fd);
}

// (fpos 'fd) -> cnt            ... Gets current file position
// (fpos 'fd 'off) -> cnt       ... Moves position relative to the current one
// (fpos 'fd 'off 'flg) -> cnt  ... Goes to the beginning (flg=NIL)
                                    otherwise to start
Thank you,

Tomas
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to