/*
 * filesize.c
 *
 */
 
#include <tcl.h>
#include <tclInt.h>
#include <tclPort.h>

int
FileSizeObjCmd(ClientData clientData,
	Tcl_Interp *interp,	int objc, Tcl_Obj *CONST objv[])
{
	Tcl_StatBuf statBuf;
	Tcl_Obj *resultObj;

	if (objc != 2) {
		Tcl_WrongNumArgs(interp, 1, objv, "<fileName>");
		return TCL_ERROR;
    }

	if (Tcl_FSConvertToPathType(interp, objv[1]) != TCL_OK) {
		return TCL_ERROR;
	}

	if (Tcl_FSStat(objv[1], &statBuf) < 0) {
		return TCL_ERROR;
	}
	resultObj = Tcl_NewWideIntObj((Tcl_WideInt)statBuf.st_size);
	Tcl_SetObjResult(interp, resultObj);

	return TCL_OK;
}


int Filesize_Init(Tcl_Interp *interp)
{
#ifdef USE_TCL_STUBS
	if (Tcl_InitStubs(interp, "8.4", 0) == NULL) {
		return TCL_ERROR;
	}
#endif

	Tcl_CreateObjCommand(interp, "filesize", FileSizeObjCmd,
			(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);

	Tcl_PkgProvide(interp, "filesize", "0.1");

	return TCL_OK;
}


/* EOF */
