Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Lachu:SystemServices
Lachu-PackageKit
0008-Refactor-get_line-routine.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0008-Refactor-get_line-routine.patch of Package Lachu-PackageKit
From fe0d4308abd9dd3f6a2bab1ab08fc64687a3949a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= <slawek@lach.art.pl> Date: Mon, 21 Sep 2020 16:20:56 +0200 Subject: [PATCH 08/46] - Refactor get_line routine - Change name of this routine to get_record - Enchance readability --- backends/zypp/pk-backend-zypp.cpp | 72 +++++++++++++++++-------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp index f58a24de7..4b0829390 100644 --- a/backends/zypp/pk-backend-zypp.cpp +++ b/backends/zypp/pk-backend-zypp.cpp @@ -1790,7 +1790,7 @@ static void message_proc(const char *msg__, intptr_t usr_p) } -static char *get_line(int fd, char *buffer) +static char *get_record(int fd, char *buffer) { int count; int curr = 0; @@ -1798,29 +1798,18 @@ static char *get_line(int fd, char *buffer) int loaded = 0; bool done = false; - do { - - buff_len += 512; - buffer = (char*)realloc(buffer, buff_len); + + + buff_len += 512; + buffer = (char*)realloc(buffer, buff_len); + + if (NULL == buffer) { - if (NULL == buffer) { + return NULL; + } + + while ((count = read(fd, buffer, buff_len - 1 - loaded)) > 0) { - return NULL; - } - - if (done || (count = read(fd, buffer, buff_len - 1 - loaded)) < 1) { - - if (!done && 0 > count) { - - close(fd); - return NULL; - } - - buffer[loaded] = '\0'; - - lseek(fd, - (loaded - curr) + 1, SEEK_CUR); - return buffer; - } curr = loaded; loaded += count; @@ -1832,12 +1821,31 @@ static char *get_line(int fd, char *buffer) if (curr < loaded && '\0' == buffer[curr]) { done = true; + break; + } + + buff_len += 512; + buffer = (char*)realloc(buffer, buff_len); + + if (NULL == buffer) { + + count = 0; + break; } + }; + + if (!done && 0 > count) { - } while (0 < count); + free(buffer); + close(fd); + return NULL; + } - free(buffer); - return NULL; + buffer[loaded] = '\0'; + + lseek(fd, - (loaded - curr) + 1, SEEK_CUR); + + return buffer; } static gboolean @@ -1852,7 +1860,7 @@ load_transaction_from_history(const char *type, const char *file) } - buffer = get_line(fd, buffer); + buffer = get_record(fd, buffer); if (NULL == buffer) { @@ -1868,7 +1876,7 @@ load_transaction_from_history(const char *type, const char *file) free(buffer); buffer = NULL; - buffer = get_line(fd, buffer); + buffer = get_record(fd, buffer); if (NULL == buffer) { @@ -1889,7 +1897,7 @@ load_transaction_from_history(const char *type, const char *file) priv->to_install.clear(); priv->to_remove.clear(); - while ((buffer = get_line(fd, buffer)) && ('\0' != buffer[0])) { + while ((buffer = get_record(fd, buffer)) && ('\0' != buffer[0])) { if (NULL == buffer) { @@ -1907,7 +1915,7 @@ load_transaction_from_history(const char *type, const char *file) buffer = NULL; } - while ((buffer = get_line(fd, buffer)) && ('\0' != buffer[0])) { + while ((buffer = get_record(fd, buffer)) && ('\0' != buffer[0])) { if (NULL == buffer) { @@ -1927,7 +1935,7 @@ load_transaction_from_history(const char *type, const char *file) struct problem problem; - while ((buffer = get_line(fd, buffer)) && ('\0' != buffer[0])) { + while ((buffer = get_record(fd, buffer)) && ('\0' != buffer[0])) { if (NULL == buffer) { @@ -1940,7 +1948,7 @@ load_transaction_from_history(const char *type, const char *file) free(buffer); buffer = NULL; - while ((buffer = get_line(fd, buffer)) && ('\0' != buffer[0])) { + while ((buffer = get_record(fd, buffer)) && ('\0' != buffer[0])) { if (NULL == buffer) { @@ -1958,7 +1966,7 @@ load_transaction_from_history(const char *type, const char *file) buffer = NULL; } - buffer = get_line(fd, buffer); + buffer = get_record(fd, buffer); if (NULL == buffer) { -- 2.32.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor