From 19ec48e9f72c7e74c65d744bd9127ab75b57cd50 Mon Sep 17 00:00:00 2001 From: Alexey Vasilyev Date: Sat, 11 Mar 2023 22:28:51 +0300 Subject: [PATCH 1/2] Implemented touch() function. --- builtin-functions/_functions.txt | 4 ++++ runtime/files.cpp | 1 + runtime/files.h | 2 ++ runtime/files_touch.cpp | 22 ++++++++++++++++++++++ runtime/files_touch.h | 9 +++++++++ 5 files changed, 38 insertions(+) create mode 100644 runtime/files_touch.cpp create mode 100644 runtime/files_touch.h diff --git a/builtin-functions/_functions.txt b/builtin-functions/_functions.txt index 9e6e139f39..1633687707 100644 --- a/builtin-functions/_functions.txt +++ b/builtin-functions/_functions.txt @@ -482,6 +482,7 @@ define('OPENSSL_DONT_ZERO_PAD_KEY', 4); function openssl_public_encrypt ($data ::: string, &$result ::: mixed, $key ::: string) ::: bool; function openssl_private_decrypt ($data ::: string, &$result ::: mixed, $key ::: string) ::: bool; + function openssl_pkey_get_private ($key ::: string, $passphrase ::: string = '') ::: string | false; function openssl_pkey_get_public ($key ::: string) ::: string | false; function openssl_sign ($data ::: string, &$signature ::: string, $priv_key_id ::: string, $signature_alg ::: int = 1) ::: bool; @@ -1620,3 +1621,6 @@ class DateTimeImmutable implements DateTimeInterface { } function getenv(string $varname = '', bool $local_only = false): mixed; + +//2022-05-01 comm644 +function touch($filename ::: string, int $mtime = 0, int $atime = 0): bool; diff --git a/runtime/files.cpp b/runtime/files.cpp index 06a346f965..45b9c57fd5 100644 --- a/runtime/files.cpp +++ b/runtime/files.cpp @@ -939,3 +939,4 @@ void free_files_lib() { dl::leave_critical_section(); } +#include "files_touch.cpp" \ No newline at end of file diff --git a/runtime/files.h b/runtime/files.h index 0da8704f05..e70c3c2460 100644 --- a/runtime/files.h +++ b/runtime/files.h @@ -72,3 +72,5 @@ Optional file_file_get_contents(const string &name); void global_init_files_lib(); void free_files_lib(); + +#include "files_touch.h" \ No newline at end of file diff --git a/runtime/files_touch.cpp b/runtime/files_touch.cpp new file mode 100644 index 0000000000..a74624c1ab --- /dev/null +++ b/runtime/files_touch.cpp @@ -0,0 +1,22 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2023 LLC Sigmalab +// Distributed under the GPL v3 License, see LICENSE.notice.txt +#include +#include +#include + +bool f$touch(const string filename, const int64_t mtime, const int64_t atime) +{ + if (FILE *file = fopen(filename.c_str(), "a+")) { + fclose(file); + } + else { + return false; + } + + time_t now = std::time(NULL); + time_t val_mtime = !mtime ? now : mtime; + time_t val_atime = !atime ? now : atime; + const utimbuf timebuf = {val_atime, val_mtime}; + return utime(filename.c_str(), &timebuf ) == 0; +} diff --git a/runtime/files_touch.h b/runtime/files_touch.h new file mode 100644 index 0000000000..13ef8cc22f --- /dev/null +++ b/runtime/files_touch.h @@ -0,0 +1,9 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2023 LLC Sigmalab +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once +#include "runtime/kphp_core.h" +#include + +bool f$touch(const string filename, const int64_t mtime=0, const int64_t atime=0); From 1d8b2afb5e864b34a6acd6e3d9d8e8fba55ce246 Mon Sep 17 00:00:00 2001 From: Alexey Vasilyev Date: Sat, 11 Mar 2023 22:30:38 +0300 Subject: [PATCH 2/2] improved diff. fixed whitespaces. --- builtin-functions/_functions.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/builtin-functions/_functions.txt b/builtin-functions/_functions.txt index 1633687707..307451ee4c 100644 --- a/builtin-functions/_functions.txt +++ b/builtin-functions/_functions.txt @@ -482,7 +482,6 @@ define('OPENSSL_DONT_ZERO_PAD_KEY', 4); function openssl_public_encrypt ($data ::: string, &$result ::: mixed, $key ::: string) ::: bool; function openssl_private_decrypt ($data ::: string, &$result ::: mixed, $key ::: string) ::: bool; - function openssl_pkey_get_private ($key ::: string, $passphrase ::: string = '') ::: string | false; function openssl_pkey_get_public ($key ::: string) ::: string | false; function openssl_sign ($data ::: string, &$signature ::: string, $priv_key_id ::: string, $signature_alg ::: int = 1) ::: bool;