Tasmota/lib/libesp32/Berry/default/be_path_tasmota_lib.c

53 lines
1.5 KiB
C
Raw Normal View History

2021-07-18 21:39:59 +01:00
/********************************************************************
** Copyright (c) 2018-2020 Guan Wenliang
** This file is part of the Berry default interpreter.
** skiars@qq.com, https://github.com/Skiars/berry
** See Copyright Notice in the LICENSE file or at
** https://github.com/Skiars/berry/blob/master/LICENSE
********************************************************************/
/********************************************************************
* Berry module `path`
*
* Minimal version of `import path`
*
*******************************************************************/
#include "be_object.h"
#include "be_strlib.h"
#include "be_mem.h"
#include "be_sys.h"
2021-09-15 21:25:36 +01:00
#include <time.h>
2021-07-18 21:39:59 +01:00
static int m_path_exists(bvm *vm)
{
const char *path = NULL;
if (be_top(vm) >= 1 && be_isstring(vm, 1)) {
path = be_tostring(vm, 1);
}
be_pushbool(vm, be_isexist(path));
be_return(vm);
}
2021-09-15 21:25:36 +01:00
extern time_t be_last_modified(void *hfile);
static int m_path_last_modified(bvm *vm)
{
if (be_top(vm) >= 1 && be_isstring(vm, 1)) {
const char *path = be_tostring(vm, 1);
void * f = be_fopen(path, "r");
if (f) {
be_pushint(vm, be_last_modified(f));
2021-09-28 21:17:11 +01:00
be_fclose(f);
2021-09-15 21:25:36 +01:00
be_return(vm);
}
}
be_return_nil(vm);
}
2021-07-18 21:39:59 +01:00
/* @const_object_info_begin
module path (scope: global, file: tasmota_path) {
exists, func(m_path_exists)
2021-09-15 21:25:36 +01:00
last_modified, func(m_path_last_modified)
2021-07-18 21:39:59 +01:00
}
@const_object_info_end */
#include "../generate/be_fixed_tasmota_path.h"