mirror of https://github.com/arendst/Tasmota.git
53 lines
1.5 KiB
C
53 lines
1.5 KiB
C
/********************************************************************
|
|
** 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"
|
|
#include <time.h>
|
|
|
|
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);
|
|
}
|
|
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));
|
|
be_fclose(f);
|
|
be_return(vm);
|
|
}
|
|
}
|
|
be_return_nil(vm);
|
|
}
|
|
|
|
/* @const_object_info_begin
|
|
module path (scope: global, file: tasmota_path) {
|
|
exists, func(m_path_exists)
|
|
last_modified, func(m_path_last_modified)
|
|
}
|
|
@const_object_info_end */
|
|
#include "../generate/be_fixed_tasmota_path.h"
|