Changeset 19467


Ignore:
Timestamp:
01/05/13 05:23:37 (11 years ago)
Author:
nit
Message:

[titan] optimize

Location:
titan/titan
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • titan/titan/about.h

    r15915 r19467  
    77        struct dvbdev* dvbnode = dvbdev;
    88
    9         text = malloc(MINMALLOC);
    10         if(text == NULL)
    11         {
    12                 err("no memory");
    13                 return 1;
    14         }
    15 
    16         tmpstr = ostrcat(_("Image"), ": ", 0, 0);
    17         tmpstr = ostrcat(tmpstr, PROGNAME, 1, 0);
    18         tmpstr = ostrcat(tmpstr, "\n", 1, 0);
    19         tmpstr = ostrcat(tmpstr, _("Version"), 1, 0);
    20         tmpstr = ostrcat(tmpstr, ": ", 1, 0);
    21         tmpstr = ostrcat(tmpstr, OVERSION, 1, 0);
    22         tmpstr = ostrcat(tmpstr, "\n", 1, 0);
    23         tmpstr = ostrcat(tmpstr, _("Copyright"), 1, 0);
    24         tmpstr = ostrcat(tmpstr, ": ", 1, 0);
    25         tmpstr = ostrcat(tmpstr, COPYRIGHT, 1, 0);
    26         tmpstr = ostrcat(tmpstr, "\n\n", 1, 0);
    27                
    28 //      snprintf(text, MINMALLOC, _("Image: %s\nVersion: %s\nCopyright: %s\n\n"), PROGNAME, OVERSION, COPYRIGHT);
    29         snprintf(text, MINMALLOC, "%s", tmpstr);
    30         free(tmpstr), tmpstr = NULL;
     9        text = ostrcat(_("Image"), ": ", 0, 0);
     10        text = ostrcat(text, PROGNAME, 1, 0);
     11        text = ostrcat(text, "\n", 1, 0);
     12        text = ostrcat(text, _("Version"), 1, 0);
     13        text = ostrcat(text, ": ", 1, 0);
     14        text = ostrcat(text, OVERSION, 1, 0);
     15        text = ostrcat(text, "\n", 1, 0);
     16        text = ostrcat(text, _("Copyright"), 1, 0);
     17        text = ostrcat(text, ": ", 1, 0);
     18        text = ostrcat(text, COPYRIGHT, 1, 0);
     19        text = ostrcat(text, "\n\n", 1, 0);
    3120               
    3221        while(dvbnode != NULL)
  • titan/titan/ca.h

    r18690 r19467  
    205205        unsigned char *tmpbuf = NULL;
    206206
    207         buf = malloc(MINMALLOC);
     207        buf = calloc(1, MINMALLOC);
    208208        if(buf == NULL)
    209209        {
     
    214214        debug(620, "send SPDU, nr %d", sessionnr);
    215215
    216         memset(buf, 0, MINMALLOC);
    217216        tmpbuf = buf;
    218217
     
    14991498        canode = dvbnode->caslot;
    15001499
    1501         buf = malloc(MINMALLOC);
     1500        buf = calloc(1, MINMALLOC);
    15021501        if(buf == NULL)
    15031502        {
     
    15051504                return;
    15061505        }
    1507         memset(buf, 0, MINMALLOC);
    15081506
    15091507        switch(canode->status)
     
    15141512                        debug(620, "status: no, slot %d", dvbnode->devnr);
    15151513
    1516                         //reset the module an wait max 10 sek
     1514                        //reset the module an wait max 10 sek
    15171515                        careseting(self, dvbnode, 0);
    15181516
  • titan/titan/channel.h

    r18431 r19467  
    317317        }
    318318
    319         newnode->name = ostrcat(name, NULL, 1, 0);
     319        newnode->name = ostrshrink(name);
    320320        //99 = tmp channel
    321321        if(newnode->servicetype != 99)
  • titan/titan/extepg.h

    r19375 r19467  
    682682        }
    683683
    684         newnode->file = ostrcat(file, NULL, 1, 0);
     684        newnode->file = ostrshrink(file);
    685685
    686686        if(last == NULL)
  • titan/titan/global.h

    r19447 r19467  
    155155        ltostr(str, val, base);
    156156
    157         return ostrcat(str, NULL, 1, 0);
     157        return ostrshrink(str);
    158158}
    159159
     
    11401140                return;
    11411141               
    1142         buf = malloc(MINMALLOC);
     1142        buf = calloc(1, MINMALLOC);
    11431143        if(buf == NULL)
    11441144        {
     
    11461146                return;
    11471147        }
    1148         memset(buf, 0, MINMALLOC);
    1149        
     1148
    11501149        fwrite(buf, MINMALLOC, 1, fd);
    11511150
     
    16991698        char* buf = NULL, *to = NULL;
    17001699
    1701         buf = malloc(MINMALLOC);
     1700        buf = calloc(1, MINMALLOC);
    17021701        if(buf == NULL)
    17031702        {
     
    17051704                return NULL;
    17061705        }
    1707         memset(buf, 0, MINMALLOC);
    17081706        to = buf;
    17091707
     
    17251723        *to = '\0';
    17261724
    1727         buf = ostrcat(buf, NULL, 1, 0);
     1725        buf = ostrshrink(buf);
    17281726        return buf;
    17291727}
     
    31793177}
    31803178
     3179char* ostrshrink(char* value)
     3180{
     3181//      debug(1000, "in");
     3182        int len = 0;
     3183        char* buf = NULL;
     3184
     3185        if(value == NULL) return NULL;
     3186
     3187        len = strlen(value);
     3188        if(len == 0) return value;
     3189
     3190        buf = malloc(len + 1);
     3191        if(buf == NULL)
     3192                return value;
     3193
     3194        memcpy(buf, value, len);
     3195        free(value);
     3196        buf[len] = '\0';
     3197
     3198        return buf;
     3199}
     3200
    31813201char* ostrcat(char* value1, char* value2, int free1, int free2)
    31823202{
     
    32203240{
    32213241        debug(1000, "in");
    3222         char *buf = NULL, *buf1 = NULL;
     3242        char *buf = NULL;
    32233243
    32243244        buf = malloc(MINMALLOC);
     
    32303250
    32313251        sprintf(buf, "%llu", value);
    3232         buf1 = ostrcat(buf, NULL, 1, 0);
    3233 
    3234         debug(1000, "out");
    3235         return buf1;
     3252        buf = ostrshrink(buf);
     3253
     3254        debug(1000, "out");
     3255        return buf;
    32363256}
    32373257
     
    32393259{
    32403260        debug(1000, "in");
    3241         char *buf = NULL, *buf1 = NULL;
     3261        char *buf = NULL;
    32423262
    32433263        buf = malloc(MINMALLOC);
     
    32493269
    32503270        sprintf(buf, "%lu", value);
    3251         buf1 = ostrcat(buf, NULL, 1, 0);
    3252 
    3253         debug(1000, "out");
    3254         return buf1;
     3271        buf = ostrshrink(buf);
     3272
     3273        debug(1000, "out");
     3274        return buf;
    32553275}
    32563276
     
    32583278{
    32593279        debug(1000, "in");
    3260         char *buf = NULL, *buf1 = NULL;
     3280        char *buf = NULL;
    32613281
    32623282        buf = malloc(MINMALLOC);
     
    32683288
    32693289        sprintf(buf, "%x", value);
    3270         buf1 = ostrcat(buf, NULL, 1, 0);
    3271 
    3272         debug(1000, "out");
    3273         return buf1;
     3290        buf = ostrshrink(buf);
     3291
     3292        debug(1000, "out");
     3293        return buf;
    32743294}
    32753295
     
    32773297{
    32783298        debug(1000, "in");
    3279         char *buf = NULL, *buf1 = NULL;
     3299        char *buf = NULL;
    32803300
    32813301        buf = malloc(MINMALLOC);
     
    32873307
    32883308        sprintf(buf, "%d", value);
    3289         buf1 = ostrcat(buf, NULL, 1, 0);
    3290 
    3291         debug(1000, "out");
    3292         return buf1;
     3309        buf = ostrshrink(buf);
     3310
     3311        debug(1000, "out");
     3312        return buf;
    32933313}
    32943314
     
    32963316{
    32973317        debug(1000, "in");
    3298         char *buf = NULL, *buf1 = NULL;
     3318        char *buf = NULL;
    32993319
    33003320        buf = malloc(MINMALLOC);
     
    33063326
    33073327        sprintf(buf, "%lld", value);
    3308         buf1 = ostrcat(buf, NULL, 1, 0);
    3309 
    3310         debug(1000, "out");
    3311         return buf1;
     3328        buf = ostrcat(buf);
     3329
     3330        debug(1000, "out");
     3331        return buf;
    33123332}
    33133333
     
    33153335{
    33163336        debug(1000, "in");
    3317         char *buf = NULL, *buf1 = NULL;
     3337        char *buf = NULL;
    33183338        char* tmpstr = NULL;
    33193339
     
    33293349
    33303350        sprintf(buf, tmpstr, value);
    3331         buf1 = ostrcat(buf, NULL, 1, 0);
     3351        buf = ostrcat(buf);
    33323352
    33333353        free(tmpstr);
    33343354        debug(1000, "out");
    3335         return buf1;
     3355        return buf;
    33363356}
    33373357
     
    36663686        if(len >= 0 && fileline[len] == '\n')
    36673687                fileline[len] = '\0';
    3668         buf1 = ostrcat(fileline, NULL, 1, 0);
     3688        buf1 = ostrshrink(fileline);
    36693689
    36703690        fclose(fd);
     
    37133733        if(len >= 0 && fileline[len] == '\n')
    37143734                fileline[len] = '\0';
    3715         buf1 = ostrcat(fileline, NULL, 1, 0);
     3735        buf1 = ostrshrink(fileline);
    37163736
    37173737        fclose(fd);
  • titan/titan/harddisk.h

    r18077 r19467  
    1313        }
    1414        snprintf(buf, MINMALLOC, "%.2f", (float)size / 2 / 1024 / 1024); //size is in 512KB blocks
    15         return buf;
     15        return ostrshrink(buf);
    1616}
    1717
  • titan/titan/header.h

    r19454 r19467  
    666666int ostrcmp(char* value1, char* value2);
    667667int ostrcasecmp(char* value1, char* value2);
     668char* ostrshrink(char* value);
    668669char* ostrcat(char* value1, char* value2, int free1, int free2);
    669670int ostrncmp(char* value1, char* value2, int count);
  • titan/titan/mediadb.h

    r19216 r19467  
    338338        }
    339339
    340         newnode->name = ostrcat(name, NULL, 1, 0);
     340        newnode->name = ostrshrink(name);
    341341
    342342        if(flag == 0) m_lock(&status.mediadbmutex, 17);
  • titan/titan/newsletter.h

    r19453 r19467  
    6060        }
    6161
    62         newnode->date = ostrcat(date, NULL, 1, 0);
    63         newnode->title = ostrcat(title, NULL, 1, 0);
    64         newnode->text = string_replace_all("\\n", "\n", text, 1);
     62        newnode->date = ostrshrink(date);
     63        newnode->title = ostrshrink(title);
     64        newnode->text = ostrshrink(text);
     65        newnode->text = string_replace_all("\\n", "\n", newnode->text, 1);
    6566
    6667        if(last == NULL)
  • titan/titan/playlist.h

    r16991 r19467  
    214214
    215215        free(file);
    216         newnode->file = ostrcat(line, NULL, 0, 0);
     216        newnode->file = ostrshrink(line);
    217217
    218218        if(last == NULL)
  • titan/titan/provider.h

    r18452 r19467  
    192192        int ret = 0;
    193193
    194         newnode = (struct provider*)malloc(sizeof(struct provider));   
     194        newnode = (struct provider*)calloc(1, sizeof(struct provider));
    195195        if(newnode == NULL)
    196196        {
     
    207207        }
    208208
    209         memset(newnode, 0, sizeof(struct provider));
    210209        status.writeprovider = 1;
    211210
     
    226225        }
    227226
    228         newnode->name = ostrcat(name, NULL, 1, 0);
     227        newnode->name = ostrshrink(name);
    229228
    230229        if(last == NULL)
  • titan/titan/rcmap.h

    r16380 r19467  
    2323                return NULL;
    2424        }
     25
    2526        key = malloc(MINMALLOC);
    2627        if(key == NULL)
     
    6061        }
    6162
    62         newnode->name = ostrcat(name, NULL, 1, 0);
     63        newnode->name = ostrshrink(name);
    6364        newnode->key = getrcconfigint(key, NULL);
    6465        free(key); key = NULL;
  • titan/titan/sat.h

    r18165 r19467  
    321321        }
    322322
    323         newnode->name = ostrcat(name, NULL, 1, 0);
     323        newnode->name = ostrshrink(name);
    324324
    325325        if(last == NULL)
  • titan/titan/sock.h

    r19036 r19467  
    462462        if(host == NULL) return NULL;
    463463
    464         ip = malloc(iplen);
     464        ip = calloc(1, iplen);
    465465        if(ip == NULL)
    466466        {
     
    468468                return NULL;
    469469        }
    470         memset(ip, 0, iplen);
    471 
    472         buf = malloc(MINMALLOC);
     470
     471        buf = calloc(1, MINMALLOC);
    473472        if(buf == NULL)
    474473        {
     
    477476                return NULL;
    478477        }
    479         memset(buf, 0, MINMALLOC);
    480478
    481479        ret = gethostbyname_r(host, &hent, buf, MINMALLOC, &result, &err);
     
    649647
    650648        //now it is time to receive the page
    651         tmpbuf = malloc(MINMALLOC);
     649        tmpbuf = calloc(1, MINMALLOC);
    652650        if(tmpbuf == NULL)
    653651        {
     
    662660                return NULL;
    663661        }
    664         memset(tmpbuf, 0, MINMALLOC);
    665662
    666663        //read one line
  • titan/titan/stream.h

    r18431 r19467  
    8989                        debug(250, "accept stream connection connfd=%d", connfd);
    9090
    91                         buf = malloc(MINMALLOC);
     91                        buf = calloc(1, MINMALLOC);
    9292                        if(buf == NULL)
    9393                        {
     
    9696                                continue;
    9797                        }
    98                         memset(buf, 0, MINMALLOC);
    9998
    10099                        debug(250, "get client data");
Note: See TracChangeset for help on using the changeset viewer.