aboutsummaryrefslogtreecommitdiffstats
path: root/app.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-27 19:07:46 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-27 19:07:46 +0000
commitc33ca69a5d99391fc96ef19996fad002a3a8712d (patch)
tree9f1e5fe39404d9956af0d7ad47e2b60637cd5c30 /app.c
parent3f422b8a43f78cc1b1336a204f34dbadbeef0ac2 (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-xapp.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/app.c b/app.c
index ebda3f765..d740b9d1a 100755
--- a/app.c
+++ b/app.c
@@ -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;
+}
+