From 73ca904974a3238b056daf89d9ab156fb27cdb3d Mon Sep 17 00:00:00 2001 From: neil Date: Mon, 29 Jun 2015 16:19:35 +0000 Subject: [PATCH] - Also examine the resized file to check it has the new size. - Return AmigaDOS return codes. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@50891 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- test/setfilesize.c | 125 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 42 deletions(-) rewrite test/setfilesize.c (77%) diff --git a/test/setfilesize.c b/test/setfilesize.c dissimilarity index 77% index 172a15bffc..1bde735809 100644 --- a/test/setfilesize.c +++ b/test/setfilesize.c @@ -1,42 +1,83 @@ -/* - Copyright © 1995-2014, The AROS Development Team. All rights reserved. - $Id$ -*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) { - BPTR fh; - LONG size; - - if (argc != 3) { - printf("usage: %s filename newsize\n", argv[0]); - return 1; - } - - fh = Open(argv[1], MODE_READWRITE); - if (fh == BNULL) { - PrintFault(IoErr(), "SetFileSize"); - return 0; - } - - size = SetFileSize(fh, atol(argv[2]), OFFSET_BEGINNING); - if (size < 0) { - PrintFault(IoErr(), "SetFileSize"); - Close(fh); - return 0; - } - - Printf("New size is %ld bytes\n", size); - - Close(fh); - - return 0; -} +/* + Copyright © 1995-2015, The AROS Development Team. All rights reserved. + $Id$ +*/ + +#include + +#include +#include + +#include +#include + +int main(int argc, char **argv) +{ + BPTR fh = BNULL; + LONG result = RETURN_OK, error = 0, size; + struct FileInfoBlock *fib; + + fib = AllocDosObject(DOS_FIB, NULL); + if (fib == NULL) + { + error = IoErr(); + result = RETURN_FAIL; + } + + if (error == 0 && argc != 3) + { + printf("Usage: %s filename newsize\n", argv[0]); + error = ERROR_REQUIRED_ARG_MISSING; + result = RETURN_WARN; + } + + if (error == 0) + { + fh = Open(argv[1], MODE_READWRITE); + if (fh == BNULL) + { + error = IoErr(); + result = RETURN_ERROR; + } + } + + if (error == 0) + { + size = atol(argv[2]); + if (SetFileSize(fh, atol(argv[2]), OFFSET_BEGINNING) != size) + { + error = IoErr(); + result = RETURN_ERROR; + } + } + + if (error == 0) + { + if (!ExamineFH(fh, fib)) + { + error = IoErr(); + result = RETURN_ERROR; + } + } + + if (error == 0) + { + Printf("New size is %ld bytes\n", fib->fib_Size); + if (fib->fib_Size != size) + { + if (fib->fib_Size > size) + error = ERROR_OBJECT_TOO_LARGE; + else + error = ERROR_UNKNOWN; + result = RETURN_ERROR; + } + } + + if (fib != NULL) + FreeDosObject(DOS_FIB, fib); + if (fh != BNULL) + Close(fh); + + PrintFault(error, "SetFileSize"); + return result; +} -- 2.11.4.GIT