[layer23] Removed the osmocom/file.h
authorAndreas.Eversberg <jolly@eversberg.eu>
Tue, 13 Jul 2010 14:54:55 +0000 (14:54 +0000)
committerAndreas.Eversberg <jolly@eversberg.eu>
Tue, 13 Jul 2010 14:54:55 +0000 (14:54 +0000)
src/host/layer23/include/osmocom/file.h [deleted file]
src/host/layer23/src/app_mobile.c
src/host/layer23/src/gsm322.c

diff --git a/src/host/layer23/include/osmocom/file.h b/src/host/layer23/include/osmocom/file.h
deleted file mode 100644 (file)
index 249064d..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef _OSMOCOM_FILE_H
-#define _OSMOCOM_FILE_H
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#define OSMOCOM_CONFDIR "/etc/osmocom/"
-#define OSMOCOM_PERM 0644
-#define OSMOCOM_FILE FILE
-static inline OSMOCOM_FILE *osmocom_fopen(const char *name, const char *mode)
-{
-       char filename[strlen(OSMOCOM_CONFDIR) + strlen(name) + 1];
-
-       if (mode[0] != 'r') {
-               int rc;
-
-               rc = mkdir(OSMOCOM_CONFDIR, OSMOCOM_PERM);
-               if (rc < 1 && errno != EEXIST)
-                       return NULL;
-       }
-
-       strcpy(filename, OSMOCOM_CONFDIR);
-       strcat(filename, name);
-       
-       return fopen(filename, mode);
-}
-#define osmocom_fread fread
-#define osmocom_fgets fgets
-#define osmocom_fwrite fwrite
-#define osmocom_feof feof
-#define osmocom_fclose fclose
-static inline int OSMOCOM_UNLINK(const char *name)
-{
-       char filename[strlen(OSMOCOM_CONFDIR) + strlen(name) + 1];
-
-       strcpy(filename, OSMOCOM_CONFDIR);
-       strcat(filename, name);
-       
-       return unlink(filename);
-}
-static inline int OSMOCOM_LINK(const char *oldname, const char *newname)
-{
-       char oldfilename[strlen(OSMOCOM_CONFDIR) + strlen(oldname) + 1];
-       char newfilename[strlen(OSMOCOM_CONFDIR) + strlen(newname) + 1];
-
-       strcpy(oldfilename, OSMOCOM_CONFDIR);
-       strcat(oldfilename, oldname);
-       strcpy(newfilename, OSMOCOM_CONFDIR);
-       strcat(newfilename, newname);
-       return link(oldfilename, newfilename);
-}
-static inline int OSMOCOM_MKSTEMP(char *name)
-{
-       char filename[strlen(OSMOCOM_CONFDIR) + strlen(name) + 1];
-       int rc;
-
-       strcpy(filename, OSMOCOM_CONFDIR);
-       strcat(filename, name);
-       
-       rc = mkstemp(filename);
-
-       memcpy(name + strlen(name) - 6, filename + strlen(filename) - 6, 6);
-
-       return rc;
-}
-static inline int OSMOCOM_CHMOD(const char *name, mode_t mode)
-{
-       char filename[strlen(OSMOCOM_CONFDIR) + strlen(name) + 1];
-
-       strcpy(filename, OSMOCOM_CONFDIR);
-       strcat(filename, name);
-       
-       return chmod(filename, mode);
-}
-
-#endif /* _OSMOCOM_FILE_H */
index 52100e0..eb50e50 100644 (file)
@@ -36,7 +36,6 @@
 #include <osmocom/logging.h>
 #include <osmocom/vty.h>
 #include <osmocom/vty/telnet_interface.h>
-#include <osmocom/file.h>
 
 #include <osmocore/msgb.h>
 #include <osmocore/talloc.h>
@@ -175,7 +174,7 @@ int l23_app_init(struct osmocom_ms *ms)
                fprintf(stderr, "Failed to parse the config file: '%s'\n",
                        config_file);
                fprintf(stderr, "Please check or create config file using: "
-                       "'touch %s%s'\n", OSMOCOM_CONFDIR, config_file);
+                       "'touch %s'\n", config_file);
                return rc;
        }
        telnet_init(l23_ctx, NULL, vty_port);
index fcc85a7..3266397 100644 (file)
@@ -33,7 +33,6 @@
 
 #include <osmocom/logging.h>
 #include <osmocom/l1ctl.h>
-#include <osmocom/file.h>
 #include <osmocom/osmocom_data.h>
 #include <osmocom/networks.h>
 #include <osmocom/vty.h>
@@ -3357,9 +3356,8 @@ int gsm322_init(struct osmocom_ms *ms)
 {
        struct gsm322_plmn *plmn = &ms->plmn;
        struct gsm322_cellsel *cs = &ms->cellsel;
-       OSMOCOM_FILE *fp;
-       char suffix[] = ".ba";
-       char filename[sizeof(ms->name) + strlen(suffix) + 1];
+       FILE *fp;
+       char filename[128];
        int i;
        struct gsm322_ba_list *ba;
        uint8_t buf[4];
@@ -3390,24 +3388,23 @@ int gsm322_init(struct osmocom_ms *ms)
                        cs->list[i].flags |= GSM322_CS_FLAG_SUPPORT;
 
        /* read BA list */
-       strcpy(filename, ms->name);
-       strcat(filename, suffix);
-       fp = osmocom_fopen(filename, "r");
+       sprintf(filename, "/etc/osmocom/%s.ba", ms->name);
+       fp = fopen(filename, "r");
        if (fp) {
                int rc;
 
-               while(!osmocom_feof(fp)) {
+               while(!feof(fp)) {
                        ba = talloc_zero(l23_ctx, struct gsm322_ba_list);
                        if (!ba)
                                return -ENOMEM;
-                       rc = osmocom_fread(buf, 4, 1, fp);
+                       rc = fread(buf, 4, 1, fp);
                        if (!rc) {
                                talloc_free(ba);
                                break;
                        }
                        ba->mcc = (buf[0] << 8) | buf[1];
                        ba->mnc = (buf[2] << 8) | buf[3];
-                       rc = osmocom_fread(ba->freq, sizeof(ba->freq), 1, fp);
+                       rc = fread(ba->freq, sizeof(ba->freq), 1, fp);
                        if (!rc) {
                                talloc_free(ba);
                                break;
@@ -3418,7 +3415,7 @@ int gsm322_init(struct osmocom_ms *ms)
                                gsm_print_mnc(ba->mnc), gsm_get_mcc(ba->mcc),
                                gsm_get_mnc(ba->mcc, ba->mnc));
                }
-               osmocom_fclose(fp);
+               fclose(fp);
        } else
                LOGP(DCS, LOGL_INFO, "No stored BA list\n");
 
@@ -3433,9 +3430,8 @@ int gsm322_exit(struct osmocom_ms *ms)
        struct gsm322_cellsel *cs = &ms->cellsel;
        struct llist_head *lh, *lh2;
        struct msgb *msg;
-       OSMOCOM_FILE *fp;
-       char suffix[] = ".ba";
-       char filename[sizeof(ms->name) + strlen(suffix) + 1];
+       FILE *fp;
+       char filename[128];
        struct gsm322_ba_list *ba;
        uint8_t buf[4];
        int i;
@@ -3463,9 +3459,8 @@ int gsm322_exit(struct osmocom_ms *ms)
        }
 
        /* store BA list */
-       strcpy(filename, ms->name);
-       strcat(filename, suffix);
-       fp = osmocom_fopen(filename, "w");
+       sprintf(filename, "/etc/osmocom/%s.ba", ms->name);
+       fp = fopen(filename, "w");
        if (fp) {
                int rc;
 
@@ -3474,14 +3469,14 @@ int gsm322_exit(struct osmocom_ms *ms)
                        buf[1] = ba->mcc & 0xff;
                        buf[2] = ba->mnc >> 8;
                        buf[3] = ba->mnc & 0xff;
-                       rc = osmocom_fwrite(buf, 4, 1, fp);
-                       rc = osmocom_fwrite(ba->freq, sizeof(ba->freq), 1, fp);
+                       rc = fwrite(buf, 4, 1, fp);
+                       rc = fwrite(ba->freq, sizeof(ba->freq), 1, fp);
                        LOGP(DCS, LOGL_INFO, "Write stored BA list (mcc=%s "
                                "mnc=%s  %s, %s)\n", gsm_print_mcc(ba->mcc),
                                gsm_print_mnc(ba->mnc), gsm_get_mcc(ba->mcc),
                                gsm_get_mnc(ba->mcc, ba->mnc));
                }
-               osmocom_fclose(fp);
+               fclose(fp);
        } else
                LOGP(DCS, LOGL_ERROR, "Failed to write BA list\n");