Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions builtin-functions/_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1620,3 +1620,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;
1 change: 1 addition & 0 deletions runtime/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,3 +939,4 @@ void free_files_lib() {
dl::leave_critical_section();
}

#include "files_touch.cpp"
2 changes: 2 additions & 0 deletions runtime/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ Optional<string> file_file_get_contents(const string &name);
void global_init_files_lib();

void free_files_lib();

#include "files_touch.h"
22 changes: 22 additions & 0 deletions runtime/files_touch.cpp
Original file line number Diff line number Diff line change
@@ -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 <ctime>
#include <sys/types.h>
#include <utime.h>

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;
}
9 changes: 9 additions & 0 deletions runtime/files_touch.h
Original file line number Diff line number Diff line change
@@ -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 <sys/types.h>

bool f$touch(const string filename, const int64_t mtime=0, const int64_t atime=0);