diff options
author | antirez <antirez> | 2005-03-05 18:51:50 +0000 |
---|---|---|
committer | antirez <antirez> | 2005-03-05 18:51:50 +0000 |
commit | 4506024d028cf2727e92fc42f996d97c103e787d (patch) | |
tree | e5c0a0318074ef5563dbc08200e10858edda079a | |
parent | da0295107f40efc0273a62127433093df38b9094 (diff) | |
download | jimtcl-4506024d028cf2727e92fc42f996d97c103e787d.zip jimtcl-4506024d028cf2727e92fc42f996d97c103e787d.tar.gz jimtcl-4506024d028cf2727e92fc42f996d97c103e787d.tar.bz2 |
ANSI I/O seek method implemented.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | jim-aio.c | 32 |
2 files changed, 35 insertions, 1 deletions
@@ -1,3 +1,7 @@ +2005-03-05 16:04 antirez + + * ChangeLog, jim.c, jim.h: Solved a problem with Jim_Length() + 2005-03-05 16:01 antirez * ChangeLog, Makefile, jim-aio.c, jim.c, jim.h: Initial version of @@ -1,7 +1,7 @@ /* Jim - ANSI I/O extension * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org> * - * $Id: jim-aio.c,v 1.1 2005/03/05 15:01:38 antirez Exp $ + * $Id: jim-aio.c,v 1.2 2005/03/05 18:51:50 antirez Exp $ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,6 +65,36 @@ static int JimAioHandlerCommand(Jim_Interp *interp, int argc, } Jim_DeleteCommand(interp, Jim_GetString(argv[0], NULL)); return JIM_OK; + } else if (Jim_CompareStringImmediate(interp, argv[1], "seek")) { + /* SEEK */ + int orig = SEEK_SET; + long offset; + if (argc != 3 && argc != 4) { + Jim_WrongNumArgs(interp, 2, argv, "offset ?origin?"); + return JIM_ERR; + } + if (argc == 4) { + if (Jim_CompareStringImmediate(interp, argv[3], "start")) + orig = SEEK_SET; + else if (Jim_CompareStringImmediate(interp, argv[3], "current")) + orig = SEEK_CUR; + else if (Jim_CompareStringImmediate(interp, argv[3], "end")) + orig = SEEK_END; + else { + Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); + Jim_AppendStrings(interp, Jim_GetResult(interp), + "bad origin \"", Jim_GetString(argv[3], NULL), + "\" must be: start, current, or end", NULL); + return JIM_ERR; + } + } + if (Jim_GetLong(interp, argv[2], &offset) != JIM_OK) + return JIM_ERR; + if (fseek(af->fp, offset, orig) == -1) { + JimAioSetError(interp); + return JIM_ERR; + } + return JIM_OK; } else if (Jim_CompareStringImmediate(interp, argv[1], "gets")) { /* GETS */ char buf[AIO_BUF_LEN]; |