Revision ba99cfc2

View differences:

libavformat/avio.c
59 59
    return 0;
60 60
}
61 61

  
62
int url_open(URLContext **puc, const char *filename, int flags)
62
int url_open_protocol (URLContext **puc, struct URLProtocol *up,
63
                       const char *filename, int flags)
63 64
{
64 65
    URLContext *uc;
65
    URLProtocol *up;
66
    const char *p;
67
    char proto_str[128], *q;
68 66
    int err;
69 67

  
70
    p = filename;
71
    q = proto_str;
72
    while (*p != '\0' && *p != ':') {
73
        /* protocols can only contain alphabetic chars */
74
        if (!isalpha(*p))
75
            goto file_proto;
76
        if ((q - proto_str) < sizeof(proto_str) - 1)
77
            *q++ = *p;
78
        p++;
79
    }
80
    /* if the protocol has length 1, we consider it is a dos drive */
81
    if (*p == '\0' || (q - proto_str) <= 1) {
82
    file_proto:
83
        strcpy(proto_str, "file");
84
    } else {
85
        *q = '\0';
86
    }
87

  
88
    up = first_protocol;
89
    while (up != NULL) {
90
        if (!strcmp(proto_str, up->name))
91
            goto found;
92
        up = up->next;
93
    }
94
    err = AVERROR(ENOENT);
95
    goto fail;
96
 found:
97 68
    uc = av_malloc(sizeof(URLContext) + strlen(filename) + 1);
98 69
    if (!uc) {
99 70
        err = AVERROR(ENOMEM);
......
117 88

  
118 89
    //We must be carefull here as url_seek() could be slow, for example for http
119 90
    if(   (flags & (URL_WRONLY | URL_RDWR))
120
       || !strcmp(proto_str, "file"))
91
       || !strcmp(up->name, "file"))
121 92
        if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0)
122 93
            uc->is_streamed= 1;
123 94
    *puc = uc;
......
127 98
    return err;
128 99
}
129 100

  
101
int url_open(URLContext **puc, const char *filename, int flags)
102
{
103
    URLProtocol *up;
104
    const char *p;
105
    char proto_str[128], *q;
106

  
107
    p = filename;
108
    q = proto_str;
109
    while (*p != '\0' && *p != ':') {
110
        /* protocols can only contain alphabetic chars */
111
        if (!isalpha(*p))
112
            goto file_proto;
113
        if ((q - proto_str) < sizeof(proto_str) - 1)
114
            *q++ = *p;
115
        p++;
116
    }
117
    /* if the protocol has length 1, we consider it is a dos drive */
118
    if (*p == '\0' || (q - proto_str) <= 1) {
119
    file_proto:
120
        strcpy(proto_str, "file");
121
    } else {
122
        *q = '\0';
123
    }
124

  
125
    up = first_protocol;
126
    while (up != NULL) {
127
        if (!strcmp(proto_str, up->name))
128
            return url_open_protocol (puc, up, filename, flags);
129
        up = up->next;
130
    }
131
    *puc = NULL;
132
    return AVERROR(ENOENT);
133
}
134

  
130 135
int url_read(URLContext *h, unsigned char *buf, int size)
131 136
{
132 137
    int ret;
libavformat/avio.h
62 62

  
63 63
typedef int URLInterruptCB(void);
64 64

  
65
int url_open_protocol (URLContext **puc, struct URLProtocol *up,
66
                       const char *filename, int flags);
65 67
int url_open(URLContext **h, const char *filename, int flags);
66 68
int url_read(URLContext *h, unsigned char *buf, int size);
67 69
int url_write(URLContext *h, unsigned char *buf, int size);

Also available in: Unified diff