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 | { |
| 10 | char *field = NULL; |
| 11 | int field_length = 0; |
| 12 | int buffer_length = 0; |
| 13 | |
| 14 | buffer_length = strlen(package_buffer); |
Glenn L McGrath | 5faef74 | 2001-04-15 12:38:12 +0000 | [diff] [blame] | 15 | |
| 16 | while ((field = strchr(&package_buffer[field_length], '\n')) != NULL) { |
| 17 | field_length = buffer_length - strlen(field); |
| 18 | if (package_buffer[field_length + 1] != ' ') { |
| 19 | break; |
| 20 | } else { |
| 21 | field_length++; |
| 22 | } |
| 23 | } |
| 24 | if (field_length == 0) { |
| 25 | return(NULL); |
| 26 | } else { |
| 27 | return(xstrndup(package_buffer, field_length)); |
| 28 | } |
| 29 | } |
| 30 | |