Skip to content

Commit 0648c09

Browse files
author
Nikita Siniachenko
committed
implemented f$file_put_contents and f$getimagesize
1 parent 1fad519 commit 0648c09

File tree

5 files changed

+453
-2
lines changed

5 files changed

+453
-2
lines changed

builtin-functions/kphp-light/stdlib/file-functions.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function fflush ($stream ::: mixed): bool;
3030
function fclose ($stream ::: mixed): bool;
3131

3232
function file_get_contents ($name ::: string) ::: string | false;
33+
function file_put_contents ($name ::: string, $content ::: mixed, $flags ::: int = 0) ::: int | false;
3334

3435
function printf ($format ::: string, ...$args) ::: int;
3536

@@ -48,8 +49,6 @@ function dirname ($name ::: string) ::: string;
4849
/** @kphp-extern-func-info stub generation-required */
4950
function file ($name ::: string) ::: string[] | false;
5051
/** @kphp-extern-func-info stub generation-required */
51-
function file_put_contents ($name ::: string, $content ::: mixed, $flags ::: int = 0) ::: int | false;
52-
/** @kphp-extern-func-info stub generation-required */
5352
function file_exists ($name ::: string) ::: bool;
5453
/** @kphp-extern-func-info stub generation-required */
5554
function filectime ($name ::: string) ::: int | false;

runtime-light/k2-platform/k2-api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ inline size_t read(k2::descriptor descriptor, size_t buf_len, void* buf) noexcep
196196
return k2_read(descriptor, buf_len, buf);
197197
}
198198

199+
inline size_t pread(k2::descriptor descriptor, size_t buf_len, void* buf, off_t offset) noexcept {
200+
return k2_pread(descriptor, buf_len, buf, offset);
201+
}
202+
199203
inline void please_shutdown(k2::descriptor descriptor) noexcept {
200204
k2_please_shutdown(descriptor);
201205
}

runtime-light/k2-platform/k2-header.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ size_t k2_write(uint64_t stream_d, size_t data_len, const void* data);
329329
*/
330330
size_t k2_read(uint64_t stream_d, size_t buf_len, void* buf);
331331

332+
/**
333+
* reads at most `buf_len` bytes to `buf` from `offset` position without modifying stream state.
334+
*
335+
* @return number of read bytes.
336+
*/
337+
size_t k2_pread(uint64_t stream_d, size_t buf_len, void* buf, off_t offset);
338+
332339
/**
333340
* Sets `StreamStatus.please_whutdown_write=true` for the component on the
334341
* opposite side (does not affect `StreamStatus` on your side).

0 commit comments

Comments
 (0)