Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #18 from jacobmarble/gnu
Browse files Browse the repository at this point in the history
Fixes for gcc.
  • Loading branch information
vitalybuka committed Jun 30, 2015
2 parents ffd61bc + 2e4662c commit ed2b581
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
24 changes: 18 additions & 6 deletions snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ char *request(void *sessp, long max_repetitions, oid *name, size_t name_length,
if (status != STAT_SUCCESS) {
char *errstr = session_error(sessp);
char *err = NULL;
asprintf(&err, "SNMP request error: %s", errstr);
free(errstr);
int failure = asprintf(&err, "SNMP request error: %s", errstr);
if (failure == -1) {
err = errstr;
} else {
free(errstr);
}
return err;
}

Expand Down Expand Up @@ -119,8 +123,12 @@ struct bulkwalk_response *bulkwalk(char *peername, char *community) {
if ((sessp = snmp_sess_open(&session)) == NULL) {
char *errstr = open_error(&session);
char *err = NULL;
asprintf(&err, "Open SNMP session error: %s", errstr);
free(errstr);
int failure = asprintf(&err, "Open SNMP session error: %s", errstr);
if (failure == -1) {
err = errstr;
} else {
free(errstr);
}
add_error(response, err);
return response;
}
Expand Down Expand Up @@ -163,8 +171,12 @@ struct bulkwalk_response *bulkwalk(char *peername, char *community) {

char *errstr = session_error(sessp);
err = NULL;
asprintf(&err, "SNMP response error (%ld): %s", subtree->errstat, errstr);
free(errstr);
int failure = asprintf(&err, "SNMP response error (%ld): %s", subtree->errstat, errstr);
if (failure == -1) {
err = errstr;
} else {
free(errstr);
}
add_error(response, err);
snmp_free_pdu(subtree);
break;
Expand Down
7 changes: 7 additions & 0 deletions snmp/snmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/

// This makes asprintf work properly under GNU.
#ifdef __GNUC__
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif // _GNU_SOURCE
#endif //__GNUC__

#include <stddef.h> // size_t
#include <stdio.h> // asprintf
#include <stdlib.h> // calloc, realloc, free
Expand Down

0 comments on commit ed2b581

Please sign in to comment.