Subversion Repositories HelenOS

Rev

Rev 3886 | Rev 4243 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3886 Rev 3912
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2008 Lukas Mejdrech
2
 * Copyright (c) 2009 Lukas Mejdrech
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
Line 29... Line 29...
29
/** @addtogroup net
29
/** @addtogroup net
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 *  A character string with measured length implementation file.
34
 *  Character string with measured length implementation.
35
 *  @see measured_strings.h
35
 *  @see measured_strings.h
36
 */
36
 */
37
 
37
 
38
#include <errno.h>
38
#include <errno.h>
39
#include <malloc.h>
39
#include <malloc.h>
Line 50... Line 50...
50
 
50
 
51
/** Computes the lengths of the measured strings in the given array.
51
/** Computes the lengths of the measured strings in the given array.
52
 *  @param strings The measured strings array to be processed. Input parameter.
52
 *  @param strings The measured strings array to be processed. Input parameter.
53
 *  @param count The measured strings array size. Input parameter.
53
 *  @param count The measured strings array size. Input parameter.
54
 *  @returns The computed sizes array.
54
 *  @returns The computed sizes array.
55
 *  @returns NULL if there is no memory left.
55
 *  @returns NULL if there is not enough memory left.
56
 */
56
 */
57
size_t *    prepare_lengths( const measured_string_ref strings, size_t count );
57
size_t *    prepare_lengths( const measured_string_ref strings, size_t count );
58
 
58
 
59
measured_string_ref measured_string_create_bulk( const char * string, size_t length ){
59
measured_string_ref measured_string_create_bulk( const char * string, size_t length ){
60
    measured_string_ref new;
60
    measured_string_ref new;
Line 89... Line 89...
89
    if(( ! ipc_data_write_receive( & callid, & length ))
89
    if(( ! ipc_data_write_receive( & callid, & length ))
90
    || ( length != sizeof( size_t ) * ( count + 1 ))){
90
    || ( length != sizeof( size_t ) * ( count + 1 ))){
91
        free( lengths );
91
        free( lengths );
92
        return EINVAL;
92
        return EINVAL;
93
    }
93
    }
94
    if( ERROR_OCCURED( ipc_data_write_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
94
    if( ERROR_OCCURRED( ipc_data_write_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
95
        free( lengths );
95
        free( lengths );
96
        return ERROR_CODE;
96
        return ERROR_CODE;
97
    }
97
    }
98
    * data = malloc( lengths[ count ] );
98
    * data = malloc( lengths[ count ] );
99
    if( !( * data )) return ENOMEM;
99
    if( !( * data )) return ENOMEM;
Line 144... Line 144...
144
    if(( ! ipc_data_read_receive( & callid, & length ))
144
    if(( ! ipc_data_read_receive( & callid, & length ))
145
    || ( length != sizeof( size_t ) * ( count + 1 ))){
145
    || ( length != sizeof( size_t ) * ( count + 1 ))){
146
        free( lengths );
146
        free( lengths );
147
        return EINVAL;
147
        return EINVAL;
148
    }
148
    }
149
    if( ERROR_OCCURED( ipc_data_read_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
149
    if( ERROR_OCCURRED( ipc_data_read_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
150
        free( lengths );
150
        free( lengths );
151
        return ERROR_CODE;
151
        return ERROR_CODE;
152
    }
152
    }
153
    free( lengths );
153
    free( lengths );
154
    for( index = 0; index < count; ++ index ){
154
    for( index = 0; index < count; ++ index ){
Line 173... Line 173...
173
    if(( phone <= 0 ) || ( ! strings ) || ( ! data ) || ( count <= 0 )){
173
    if(( phone <= 0 ) || ( ! strings ) || ( ! data ) || ( count <= 0 )){
174
        return EINVAL;
174
        return EINVAL;
175
    }
175
    }
176
    lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 ));
176
    lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 ));
177
    if( ! lengths ) return ENOMEM;
177
    if( ! lengths ) return ENOMEM;
178
    if( ERROR_OCCURED( ipc_data_read_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){
178
    if( ERROR_OCCURRED( ipc_data_read_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){
179
        free( lengths );
179
        free( lengths );
180
        return ERROR_CODE;
180
        return ERROR_CODE;
181
    }
181
    }
182
    * data = malloc( lengths[ count ] );
182
    * data = malloc( lengths[ count ] );
183
    if( !( * data )) return ENOMEM;
183
    if( !( * data )) return ENOMEM;
Line 213... Line 213...
213
    if(( phone <= 0 ) || ( ! strings ) || ( count <= 0 )){
213
    if(( phone <= 0 ) || ( ! strings ) || ( count <= 0 )){
214
        return EINVAL;
214
        return EINVAL;
215
    }
215
    }
216
    lengths = prepare_lengths( strings, count );
216
    lengths = prepare_lengths( strings, count );
217
    if( ! lengths ) return ENOMEM;
217
    if( ! lengths ) return ENOMEM;
218
    if( ERROR_OCCURED( ipc_data_write_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){
218
    if( ERROR_OCCURRED( ipc_data_write_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){
219
        free( lengths );
219
        free( lengths );
220
        return ERROR_CODE;
220
        return ERROR_CODE;
221
    }
221
    }
222
    free( lengths );
222
    free( lengths );
223
    for( index = 0; index < count; ++ index ){
223
    for( index = 0; index < count; ++ index ){