Return the specified INFO field from the INFO command output "info". * A new buffer is allocated for the result, that needs to be free'd. * If the field is not found NULL is returned. */
| 7924 | * A new buffer is allocated for the result, that needs to be free'd. |
| 7925 | * If the field is not found NULL is returned. */ |
| 7926 | static char *getInfoField(char *info, char *field) { |
| 7927 | char *p = strstr(info,field); |
| 7928 | char *n1, *n2; |
| 7929 | char *result; |
| 7930 | |
| 7931 | if (!p) return NULL; |
| 7932 | p += strlen(field)+1; |
| 7933 | n1 = strchr(p,'\r'); |
| 7934 | n2 = strchr(p,','); |
| 7935 | if (n2 && n2 < n1) n1 = n2; |
| 7936 | result = zmalloc(sizeof(char)*(n1-p)+1); |
| 7937 | memcpy(result,p,(n1-p)); |
| 7938 | result[n1-p] = '\0'; |
| 7939 | return result; |
| 7940 | } |
| 7941 | |
| 7942 | /* Like the above function but automatically convert the result into |
| 7943 | * a long. On error (missing field) LONG_MIN is returned. */ |
no test coverage detected