528
fileId = open(fileName, O_RDONLY, 0);
530
Tcl_AppendResult(interp, "couldn't read file \"", fileName,
531
"\": ", Tcl_PosixError(interp), (char *) NULL);
534
if (fstat(fileId, &statBuf) == -1) {
535
Tcl_AppendResult(interp, "couldn't stat file \"", fileName,
536
"\": ", Tcl_PosixError(interp), (char *) NULL);
540
cmdBuffer = (char *) ckalloc((unsigned) statBuf.st_size+1);
541
size = read(fileId, cmdBuffer, (size_t) statBuf.st_size);
529
chan = Tcl_OpenFileChannel(interp, fileName, "r", 0);
534
size = Tcl_Seek(chan, 0, SEEK_END);
536
Tcl_AppendResult(interp, "couldn't seek to end of file \"", fileName,
537
"\": ", Tcl_PosixError(interp), (char *) NULL);
538
Tcl_Close(interp, chan);
542
/* seek back to beginning */
543
if (Tcl_Seek(chan, 0, SEEK_SET) == -1) {
547
cmdBuffer = (char *) ckalloc((unsigned) size+1);
548
size = Tcl_Read(chan, cmdBuffer, size);
543
550
Tcl_AppendResult(interp, "error in reading file \"", fileName,
544
"\": ", Tcl_PosixError(interp), (char *) NULL);
551
"\": ", Tcl_PosixError(interp), (char *) NULL);
552
Tcl_Close(interp,chan);
548
if (close(fileId) != 0) {
556
if (Tcl_Close(interp,chan) != TCL_OK) {
549
557
Tcl_AppendResult(interp, "error closing file \"", fileName,
550
"\": ", Tcl_PosixError(interp), (char *) NULL);
558
"\": ", Tcl_PosixError(interp), (char *) NULL);
553
561
cmdBuffer[size] = 0;