Glenn L McGrath | ee0d93e | 2001-04-21 10:26:15 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
Glenn L McGrath | 5faef74 | 2001-04-15 12:38:12 +0000 | [diff] [blame] | 2 | #include <string.h> |
| 3 | #include "libbb.h" |
| 4 | |
| 5 | /* |
| 6 | * Returns a [multi-line] package field |
| 7 | */ |
| 8 | extern char *read_package_field(const char *package_buffer) |
| 9 | { |
Glenn L McGrath | 5faef74 | 2001-04-15 12:38:12 +0000 | [diff] [blame] | 10 | int field_length = 0; |
| 11 | int buffer_length = 0; |
| 12 | |
Glenn L McGrath | 481d19b | 2001-07-11 15:43:03 +0000 | [diff] [blame^] | 13 | if (package_buffer == NULL) { |
Glenn L McGrath | 5faef74 | 2001-04-15 12:38:12 +0000 | [diff] [blame] | 14 | return(NULL); |
Glenn L McGrath | 5faef74 | 2001-04-15 12:38:12 +0000 | [diff] [blame] | 15 | } |
Glenn L McGrath | 481d19b | 2001-07-11 15:43:03 +0000 | [diff] [blame^] | 16 | buffer_length = strlen(package_buffer); |
| 17 | field_length = strcspn(package_buffer, "\n"); |
| 18 | while (field_length < buffer_length) { |
| 19 | if (package_buffer[field_length + 1] != ' ') { |
| 20 | return(xstrndup(package_buffer, field_length)); |
| 21 | } |
| 22 | field_length++; |
| 23 | field_length += strcspn(&package_buffer[field_length], "\n"); |
| 24 | } |
| 25 | return(xstrdup(package_buffer)); |
Glenn L McGrath | 5faef74 | 2001-04-15 12:38:12 +0000 | [diff] [blame] | 26 | } |
| 27 | |