diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-02-27 19:07:46 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-02-27 19:07:46 +0000 |
commit | c33ca69a5d99391fc96ef19996fad002a3a8712d (patch) | |
tree | 9f1e5fe39404d9956af0d7ad47e2b60637cd5c30 /app.c | |
parent | 3f422b8a43f78cc1b1336a204f34dbadbeef0ac2 (diff) |
Merge mog's ReadFile application (bug #3670)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5099 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'app.c')
-rwxr-xr-x | app.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -1393,3 +1393,37 @@ int ast_ivr_menu_run(struct ast_channel *chan, struct ast_ivr_menu *menu, void * res = 0; return res; } + +char *ast_read_textfile(const char *filename) +{ + int fd; + char *output=NULL; + struct stat filesize; + int count=0; + int res; + if(stat(filename,&filesize)== -1){ + ast_log(LOG_WARNING,"Error can't stat %s\n", filename); + return NULL; + } + count=filesize.st_size + 1; + fd = open(filename, O_RDONLY); + if (fd < 0) { + ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno)); + return NULL; + } + output=(char *)malloc(count); + if (output) { + res = read(fd, output, count - 1); + if (res == count - 1) { + output[res] = '\0'; + } else { + ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno)); + free(output); + output = NULL; + } + } else + ast_log(LOG_WARNING, "Out of memory!\n"); + close(fd); + return output; +} + |