summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/phpdbg_list.c
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2014-06-29 12:49:10 +0200
committerBob Weinand <bobwei9@hotmail.com>2014-06-29 12:49:10 +0200
commit1dd3bab1dfd3fc9b62e4f1e8b5bea347ff3f995b (patch)
tree1ba5e2b40a3d5b779e624254e6433f1a73d033df /sapi/phpdbg/phpdbg_list.c
parent959a006d6149b60278cd76a5289a6ecda925ed03 (diff)
parent58c69746e585312f73163d749bd5613cd21c9a1b (diff)
downloadphp-git-1dd3bab1dfd3fc9b62e4f1e8b5bea347ff3f995b.tar.gz
Merge sapi/phpdbg into PHP-5.6
Diffstat (limited to 'sapi/phpdbg/phpdbg_list.c')
-rw-r--r--sapi/phpdbg/phpdbg_list.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c
index 037c6c38b2..e8db4e605c 100644
--- a/sapi/phpdbg/phpdbg_list.c
+++ b/sapi/phpdbg/phpdbg_list.c
@@ -130,14 +130,14 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig
char *opened = NULL;
char buffer[8096] = {0,};
long line = 0;
-
+
php_stream *stream = NULL;
if (VCWD_STAT(filename, &st) == FAILURE) {
phpdbg_error("Failed to stat file %s", filename);
return;
}
-
+
stream = php_stream_open_wrapper(filename, "rb", USE_PATH, &opened);
if (!stream) {
@@ -145,11 +145,17 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig
return;
}
+ if (offset < 0) {
+ count += offset;
+ offset = 0;
+ }
+
while (php_stream_gets(stream, buffer, sizeof(buffer)) != NULL) {
+ long linelen = strlen(buffer);
+
++line;
- if (!offset || offset <= line) {
- /* Without offset, or offset reached */
+ if (offset <= line) {
if (!highlight) {
phpdbg_write("%05ld: %s", line, buffer);
} else {
@@ -159,10 +165,15 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig
phpdbg_write(">%05ld: %s", line, buffer);
}
}
+
+ if (buffer[linelen - 1] != '\n') {
+ phpdbg_write("\n");
+ }
}
-
- if ((count + (offset-1)) == line)
+
+ if (count > 0 && count + offset - 1 < line) {
break;
+ }
}
php_stream_close(stream);