Changeset 992 for trunk/base


Ignore:
Timestamp:
Oct 8, 2002, 11:19:42 AM (22 years ago)
Author:
kevin
Message:

optimized exec cat to fcopy in reinplace
ftruncate(2) original file after performing substitutions
added ftruncate(2) command to Pextlib.c

Location:
trunk/base/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/pextlib1.0/Pextlib.c

    r816 r992  
    261261}
    262262
     263/* XXX: cannot set eof > 2GB */
     264int FtruncateCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
     265{
     266        int fd, ret;
     267        long eof = 0;
     268        char *res;
     269        Tcl_Channel channel;
     270        ClientData handle;
     271
     272        if (objc > 3) {
     273                Tcl_WrongNumArgs(interp, 1, objv, "channelId eof");
     274                return TCL_ERROR;
     275        }
     276
     277        if ((channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL)) == NULL)
     278        return TCL_ERROR;
     279
     280        if (Tcl_GetChannelHandle(channel, TCL_READABLE|TCL_WRITABLE, &handle) != TCL_OK) {
     281                Tcl_SetResult(interp, "error getting channel handle", TCL_STATIC);
     282                return TCL_ERROR;
     283        }
     284        fd = (int) handle;
     285
     286        if (Tcl_GetLongFromObj(interp, objv[2], &eof) != TCL_OK) {
     287                return TCL_ERROR;
     288        }
     289
     290        if ((ret = ftruncate(fd, eof)) != 0)
     291        {
     292                switch(errno) {
     293                        case EBADF:
     294                                res = "EBADF";
     295                                break;
     296                        case EINVAL:
     297                                res = "EINVAL";
     298                                break;
     299                        default:
     300                                res = strerror(errno);
     301                                break;
     302                }
     303                Tcl_SetResult(interp, (void *) res, TCL_STATIC);
     304                return TCL_ERROR;
     305        }
     306        return TCL_OK;
     307}
     308
    263309int ReaddirCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
    264310{
     
    345391        Tcl_CreateObjCommand(interp, "system", SystemCmd, NULL, NULL);
    346392        Tcl_CreateObjCommand(interp, "flock", FlockCmd, NULL, NULL);
     393        Tcl_CreateObjCommand(interp, "ftruncate", FtruncateCmd, NULL, NULL);
    347394        Tcl_CreateObjCommand(interp, "readdir", ReaddirCmd, NULL, NULL);
    348395        Tcl_CreateObjCommand(interp, "strsed", StrsedCmd, NULL, NULL);
  • trunk/base/src/port1.0/portutil.tcl

    r989 r992  
    325325    seek $input 0
    326326
    327     if {[catch {exec cat <@$output >@$input 2>/dev/null} error]} {
     327        # copy from strsed output back into the input
     328    if {[catch {fcopy $output $input} error]} {
    328329        ui_error "reinplace: $error"
    329330        close $output
     
    332333        return -code error "reinplace failed"
    333334    }
     335       
     336        set eof [file size "$tmpfile"]
     337        puts "$tmpfile $eof"
     338        ftruncate $input $eof
    334339
    335340    close $output
Note: See TracChangeset for help on using the changeset viewer.