~ubuntu-branches/ubuntu/jaunty/avahi/jaunty-updates

« back to all changes in this revision

Viewing changes to avahi-common/alternative.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-09-03 20:25:37 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20060903202537-syi99j0tijm9bldv
Tags: 0.6.13-2ubuntu1
* Merge with Debian, UVF Exception granted by Colin Watson
* debian/patches/03_foreground-console.patch:
  + Allow only foreground users access to the avahi-set-host-name utility as
    we don't use the "netdev" group anywhere. Thanks to Colin Watson for the
    hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: alternative.c 299 2005-08-12 00:25:52Z lennart $ */
 
1
/* $Id: alternative.c 1250 2006-08-21 20:53:24Z lennart $ */
2
2
 
3
3
/***
4
4
  This file is part of avahi.
32
32
#include "malloc.h"
33
33
 
34
34
char * avahi_alternative_host_name(const char *s) {
35
 
    const char *p, *e;
 
35
    const char *e;
36
36
    char *r;
37
37
 
38
38
    assert(s);
39
39
 
40
 
    e = s;
41
 
    
42
 
    for (p = s; *p; p++)
43
 
        if (!isdigit(*p))
44
 
            e = p+1;
45
 
 
46
 
    if (*e) {
 
40
    e = strrchr(s, '-');
 
41
 
 
42
    if (e) {
 
43
        const char *p;
 
44
        
 
45
        for (p = e+1; *p; p++)
 
46
            if (!isdigit(*p)) {
 
47
                e = NULL;
 
48
                break;
 
49
            }
 
50
 
 
51
        if (e && (*(e+1) == '0' || (*(e+1) == 0)))
 
52
            e = NULL;
 
53
    }
 
54
 
 
55
    if (e) {
47
56
        char *c;
48
57
 
 
58
        e++;
 
59
        
49
60
        if (!(c = avahi_strndup(s, e-s)))
50
61
            return NULL;
51
62
 
53
64
        avahi_free(c);
54
65
        
55
66
    } else
56
 
        r = avahi_strdup_printf("%s2", s);
 
67
        r = avahi_strdup_printf("%s-2", s);
57
68
    
58
69
    return r;
59
70
}
76
87
                e = NULL;
77
88
                break;
78
89
            }
 
90
 
 
91
        if (e && (*e == '0' || *e == 0))
 
92
            e = NULL;
79
93
    }
80
94
    
81
95
    if (e) {