vmstdlib_sdk.h
21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
#ifndef VMSTDLIB_SDK_H_
#define VMSTDLIB_SDK_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdarg.h>
#include "vmsys.h"
#define VM_CACHE_SIZE 4096
#if defined(__MRE_COMPILER_RVCT__) || defined(__MRE_COMPILER_GCC__)
#undef vsprintf
#undef sprintf
#undef sscanf
int vm_vsprintf(char *buf, const char *fmt, va_list args);
int vm_sprintf( char * buf, const char * fmt, ... );
int vm_sscanf(const char *str, const char *format, ...);
#define vsprintf vm_vsprintf
#define sprintf vm_sprintf
#define sscanf vm_sscanf
#endif
/**
* cache structure to transfer block io mode to stream io mode
*/
struct vm_cache_t {
VMINT eof; /* end of stream */
VMINT avail; /* data still available from stream */
VMINT count; /* number of byte of remaining data from stream */
VMUINT8 buf[VM_CACHE_SIZE]; /* data buffer */
};
typedef struct vm_cache_t vm_cache_t;
/*****************************************************************************
* FUNCTION
* strtoi
* DESCRIPTION
* transfer a number format from string to integer.
* PARAMETERS
* s : [IN] string to be transfered.
* RETURNS
* result of transition. -1 means failed.
*****************************************************************************/
int strtoi(char* s);
/*****************************************************************************
* FUNCTION
* vm_get_filename
* DESCRIPTION
* get file name from full path.
* PARAMETERS
* path: [IN] full path string encoding with UCS2.
* filename : [OUT] output file name encoding with UCS2.
*****************************************************************************/
void vm_get_filename(VMWSTR path, VMWSTR filename);
/*****************************************************************************
* FUNCTION
* vm_get_path
* DESCRIPTION
* get file path from full path.
* PARAMETERS
* fullpath: [IN] full path string encoding with UCS2.
* path : [OUT] output file path encoding with UCS2.
* RETURNS
* 0 means successfully
*****************************************************************************/
VMINT vm_get_path(VMWSTR fullpath, VMWSTR path);
/*****************************************************************************
* FUNCTION
* get_today_from_2000
* DESCRIPTION
* get the number of day from 2000/01/01 to now.
* RETURNS
* number of day, -1 means failed.
*****************************************************************************/
VMINT get_today_from_2000(void);
/*****************************************************************************
* FUNCTION
* vm_upper_case
* DESCRIPTION
* convert the lower case character to upper case character
* PARAMETERS
* dst : [OUT] output the upper case of string
* src : [IN] string to be converted.
*****************************************************************************/
void vm_upper_case(char* dst, char* src);
/*****************************************************************************
* FUNCTION
* vm_upper_case
* DESCRIPTION
* convert the upper case character to lower case character
* PARAMETERS
* dst: [OUT] output the lower case of string
* src : [IN] string to be converted.
*****************************************************************************/
void vm_lower_case(char* dst, char* src);
/*****************************************************************************
* FUNCTION
* vm_string_equals_ignore_case
* DESCRIPTION
* compare string without case sensitive
* PARAMETERS
* s1: [IN] the first string.
* s2 : [IN] the second string.
* RETURNS
* 0 means the two string are same, -1 means they are different.
*****************************************************************************/
VMINT vm_string_equals_ignore_case(const char *s1, const char *s2);
/*****************************************************************************
* FUNCTION
* vm_write_cache
* DESCRIPTION
* write data to cache by stream mode.
* PARAMETERS
* cache: [IN] cache pointer.
* buf : [IN] buffer address.
* buf_len : [IN] buffer length.
* RETURNS
* number of bytes written
*****************************************************************************/
VMINT vm_write_cache(vm_cache_t *cache, void *buf, VMINT buf_len);
/*****************************************************************************
* FUNCTION
* vm_read_cache
* DESCRIPTION
* read data from cache by stream mode.
* PARAMETERS
* cache: [IN] cache pointer.
* buf : [OUT] buffer address.
* buf_size : [IN] buffer size
* len : [IN] number of bytes to read.
* RETURNS
* number of bytes read
*****************************************************************************/
VMINT vm_read_cache(vm_cache_t *cache, void *buf, VMINT buf_size, VMINT len);
/*****************************************************************************
* FUNCTION
* vm_cache_read_char
* DESCRIPTION
* read a character from cache by stream mode.
* PARAMETERS
* cache: [IN] cache pointer.
* ch : [OUT] character.
* RETURNS
* 0 means succeed, else return error code.
*****************************************************************************/
VMINT vm_cache_read_char(vm_cache_t *cache, char *ch);
/*****************************************************************************
* FUNCTION
* vm_get_cache_free_space
* DESCRIPTION
* get free space of cache.
* PARAMETERS
* cache: [IN] cache pointer.
* RETURNS
* number of byte of free space
*****************************************************************************/
VMINT vm_get_cache_free_space(vm_cache_t *cache);
/*****************************************************************************
* FUNCTION
* vm_read_line
* DESCRIPTION
* read a line of string from cache.
* PARAMETERS
* line: [OUT] string pointer to read
* size : [IN] line buffer size
* cache : [IN] cache pointer.
* RETURNS
* 0 means succeed, else return error code.
*****************************************************************************/
VMINT vm_read_line(char* line, VMINT size, vm_cache_t* cache);
/* DOM-NOT_FOR_SDK-START */
/*****************************************************************************
* FUNCTION
* vm_memcpy
* DESCRIPTION
* memory copy.
* PARAMETERS
* dst: [OUT] destination data buffer.
* src : [IN] source data buffer.
* count : [IN] number of byte to be copied.
*****************************************************************************/
void vm_memcpy(void* dst, void* src, VMINT count);
/* DOM-NOT_FOR_SDK-END */
/**
* dynamic array
*/
typedef struct _vm_dyn_array_t {
/**
* size of block.
*/
VMINT block_size;
/**
* initial size.
*/
VMINT init_size;
/**
* increased size.
*/
VMINT inc_size;
/**
* count of saved block
*/
VMINT count;
/**
* capacity of the array
*/
VMINT capacity;
/**
*pointer of array
*/
void *ptr;
} vm_dyn_array_t;
/*****************************************************************************
* FUNCTION
* vm_create_dyn_array
* DESCRIPTION
* create dynamic array.
* PARAMETERS
* init_size: [IN] initial size of dynamic array.
* inc_size : [IN] increased size each time
* block_size : [IN] structure size of data stored in the array
* RETURNS
* 0 means succeed, else return error code.
*****************************************************************************/
vm_dyn_array_t* vm_create_dyn_array(VMINT init_size, VMINT inc_size, VMINT block_size);
/*****************************************************************************
* FUNCTION
* vm_dyn_array_add
* DESCRIPTION
* add new data to the end of dynamic array .
* PARAMETERS
* array: [IN] array pointer.
* data : [IN] data to be added.
* RETURNS
* 0 means succeed, else return error code.
*****************************************************************************/
VMINT vm_dyn_array_add(vm_dyn_array_t *array, void* data);
/*****************************************************************************
* FUNCTION
* vm_dyn_array_del
* DESCRIPTION
* delete the data item of specified index of the array .
* PARAMETERS
* array: [IN] array pointer.
* idx : [IN] index to be deleted.
* RETURNS
* 0 means succeed, else return error code.
*****************************************************************************/
VMINT vm_dyn_array_del(vm_dyn_array_t *array, VMINT idx);
/*****************************************************************************
* FUNCTION
* vm_dyn_array_del_all
* DESCRIPTION
* delete all the data from the specified array .
* PARAMETERS
* array: [IN] array pointer.
* RETURNS
* 0 means succeed, else return error code.
*****************************************************************************/
VMINT vm_dyn_array_del_all(vm_dyn_array_t *array);
/*****************************************************************************
* FUNCTION
* vm_free_dyn_array
* DESCRIPTION
* free the memory of the dynamic array .
* PARAMETERS
* array: [IN] array pointer.
*****************************************************************************/
void vm_free_dyn_array(vm_dyn_array_t *array);
/**
* stack operation succeed
*/
#define STACK_OPERATE_SUCCESS (0)
/**
* stack operation fail
*/
#define STACK_PARAM_ERROR (-1)
/**
* stack operation fail for lack of resource
*/
#define STACK_LEAK_RESOUCE (-2)
/**
* stack push fail for overflow
*/
#define STACK_PUSH_OVERFLOW (-3)
/**
* stack pop fail for empty stack
*/
#define STACK_OPERATE_EMPTY_STACK (-4)
/**
* stack operation fail for handler error
*/
#define STACK_HANDLE_ERROR (-5)
/*****************************************************************************
* FUNCTION
* vm_create_array_stack
* DESCRIPTION
* create an array stack, when not use this, please use vm_destory_stack to destroy it.
* PARAMETERS
* capability : [IN] stack's capability.
* handle : [OUT] the handle of stack.
* RETURNS
* create an array stack success or not.
* RETURN VALUES
* STACK_OPERATE_SUCCESS : create stack success.
* STACK_PARAM_ERROR : parameter is wrong.
* STACK_LEAK_RESOUCE : resource error.
*****************************************************************************/
VMINT vm_create_array_stack(VMINT capability, VMINT* handle);
/*****************************************************************************
* FUNCTION
* vm_create_linked_stack
* DESCRIPTION
* create an linked stack, memory will dynamicly allocate,when not use this, please use vm_destory_stack to destroy it.
* PARAMETERS
* capability : [IN] stack's capability.
* handle : [OUT] the handle of stack.
* RETURNS
* create an linked stack success or not.
* RETURN VALUES
* STACK_OPERATE_SUCCESS : create stack success.
* STACK_PARAM_ERROR : parameter is wrong.
* STACK_LEAK_RESOUCE : resource error.
*****************************************************************************/
VMINT vm_create_linked_stack(VMINT capability, VMINT* handle);
/*****************************************************************************
* FUNCTION
* vm_is_empty_stack
* DESCRIPTION
* check stack empty or not.
* PARAMETERS
* stackHandle : [IN] stack's handle when created by vm_create_linked_stack.
* RETURNS
* stack empty or not.
* RETURN VALUES
* FALSE : stack is not empty.
* TRUE : stack is empty.
*****************************************************************************/
VMINT vm_is_empty_stack(VMINT stackHandle);
/*****************************************************************************
* FUNCTION
* vm_push_stack
* DESCRIPTION
* push data to stack.
* PARAMETERS
* stackHandle : [IN] stack's handle.
* ptr : [IN] data for pushing.
* RETURNS
* push data to stack success or not.
* RETURN VALUES
* STACK_OPERATE_SUCCESS : push data success.
* STACK_PUSH_OVERFLOW : stack is full.
* STACK_LEAK_RESOUCE : memory is not enough.
* STACK_HANDLE_ERROR : stackHandle is wrong.
*****************************************************************************/
VMINT vm_push_stack(VMINT stackHandle, void* ptr);
/*****************************************************************************
* FUNCTION
* vm_popup_stack
* DESCRIPTION
* popup data from stack.
* PARAMETERS
* stackHandle : [IN] stack's handle.
* ptr : [OUT] data get from stack.
* RETURNS
* popup data success or not.
* RETURN VALUES
* STACK_OPERATE_SUCCESS : popup data success.
* STACK_OPERATE_EMPTY_STACK : stack is empty.
* STACK_HANDLE_ERROR : stackHandle is wrong.
*****************************************************************************/
VMINT vm_popup_stack(VMINT stackHandle, void** ptr);
/*****************************************************************************
* FUNCTION
* vm_peek_stack
* DESCRIPTION
* get next data from stack but not popup.
* PARAMETERS
* stackHandle : [IN] stack's handle.
* ptr : [OUT] data get from stack.
* RETURNS
* get next data from stack success or not.
* RETURN VALUES
* STACK_OPERATE_SUCCESS : popup data success.
* STACK_OPERATE_EMPTY_STACK : stack is empty.
* STACK_HANDLE_ERROR : stackHandle is wrong.
*****************************************************************************/
VMINT vm_peek_stack(VMINT stackHandle, void** ptr);
/*****************************************************************************
* FUNCTION
* vm_reset_stack
* DESCRIPTION
* clear all stack's data.
* PARAMETERS
* stackHandle : [IN] stack's handle.
* RETURNS
* clear all stack's data success or not.
* RETURN VALUES
* STACK_OPERATE_SUCCESS : clear data success.
* STACK_HANDLE_ERROR : stackHandle is wrong.
*****************************************************************************/
VMINT vm_reset_stack(VMINT stackHandle);
/*****************************************************************************
* FUNCTION
* vm_is_exist_stack
* DESCRIPTION
* check data in or not in stack.
* PARAMETERS
* stackHandle : [IN] stack's handle.
* ptr : [IN] data.
* RETURNS
* return data in or not in stack.
* RETURN VALUES
* TRUE : in stack.
* FALSE : not in stack.
*****************************************************************************/
VMINT vm_is_exist_stack(VMINT stackHandle, void* ptr);
/*****************************************************************************
* FUNCTION
* vm_destroy_stack
* DESCRIPTION
* check data in or not in stack.
* PARAMETERS
* stackHandle : [IN] stack's handle.
* RETURNS
* destroy stack success or not.
* RETURN VALUES
* STACK_OPERATE_SUCCESS : destroy stack success.
* STACK_HANDLE_ERROR : stackHandle is wrong.
*****************************************************************************/
VMINT vm_destroy_stack(VMINT stackHandle);
/*****************************************************************************
* FUNCTION
* vm_ends_with
* DESCRIPTION
* check specified string is end with specified string
* PARAMETERS
* s1 : [IN] string to check
* s2 : [IN] ending string
* RETURNS
* 0 if s1 ended with s2, else return others.
*****************************************************************************/
VMINT vm_ends_with(const char *s1, const char *s2);
/*****************************************************************************
* FUNCTION
* vm_ends_with
* DESCRIPTION
* check specified string is end with specified string, and both of the two strings are encoding with UCS2
* PARAMETERS
* s1 : [IN] string to check
* s2 : [IN] ending string
* RETURNS
* 0 if s1 ended with s2, else return others.
*****************************************************************************/
VMINT vm_wends_with(const VMWSTR s1, const VMWSTR s2);
/* DOM-NOT_FOR_SDK-START */
/*****************************************************************************
* FUNCTION
* vm_tmp_filename
* DESCRIPTION
* generate a temp file name which will be unique.
* PARAMETERS
* prefix : [IN] prefix to temp file name, normally is path.
* filename : [OUT] temp file name length is 128 including '\0'.
*****************************************************************************/
void vm_tmp_filename(char* prefix, char* filename);
/* DOM-NOT_FOR_SDK-END */
/*****************************************************************************
* FUNCTION
* vm_safe_wstrcpy
* DESCRIPTION
* safe wstrcpy. When destination buffer is not enough, the extra part will be cut.
* PARAMETERS
* dest : [OUT] destination string.
* size : [IN] length of string.
* src : [IN] source string.
* RETURNS
* length of string copied actually.
*****************************************************************************/
VMINT vm_safe_wstrcpy(VMWSTR dest, VMINT size, VMWSTR src);
#define wstrlen vm_wstrlen
/*****************************************************************************
* FUNCTION
* vm_wstrcpy
* DESCRIPTION
* get the length of UCS2 string.
* PARAMETERS
* s : [IN] string to be checked teminated with '\0'.
* RETURNS
* length of string.
*****************************************************************************/
VMINT vm_wstrlen(VMWSTR s);
#define wstrcpy vm_wstrcpy
/*****************************************************************************
* FUNCTION
* vm_wstrcpy
* DESCRIPTION
* UCS2 string copy
* PARAMETERS
* dest : [OUT] destination string.
* src : [IN] source string.
* RETURNS
* length of string copied actually.
*****************************************************************************/
VMINT vm_wstrcpy(VMWSTR dst, const VMWSTR src);
#define wstrcat vm_wstrcat
/*****************************************************************************
* FUNCTION
* vm_wstrcat
* DESCRIPTION
* UCS2 string append.
* PARAMETERS
* dest : [OUT] destination string.
* src : [IN] source string.
*****************************************************************************/
VMINT vm_wstrcat(VMWSTR dst, const VMWSTR src);
#define wstrncpy vm_wstrncpy
/*****************************************************************************
* FUNCTION
* vm_wstrncpy
* DESCRIPTION
* UCS2 string N copy
* PARAMETERS
* dest : [OUT] destination string.
* src : [IN] source string.
* length : [IN] lenth of string to be copied.
* RETURNS
* length of string copied actually.
*****************************************************************************/
VMINT vm_wstrncpy(VMWSTR dst, const VMWSTR src, VMINT length);
#define wstrcmp vm_wstrcmp
/*****************************************************************************
* FUNCTION
* vm_wstrcmp
* DESCRIPTION
* UCS2 string compare
* PARAMETERS
* str_1 : [IN] string 1
* str_2 : [IN] string 2
* RETURNS
* 0 means the two string are same, non-zero means they are different.
*****************************************************************************/
VMINT vm_wstrcmp(VMWSTR str_1, VMWSTR str_2);
/* DOM-NOT_FOR_SDK-START */
/*****************************************************************************
* FUNCTION
* vm_wstrcmp_ignore_case
* DESCRIPTION
* UCS2 string compare without case sensitive
* PARAMETERS
* str_1 : [IN] string 1
* str_2 : [IN] string 2
* RETURNS
* 0 means the two string are same, non-zero means they are different.
*****************************************************************************/
VMINT vm_wstrcmp_ignore_case(VMWSTR str_1, VMWSTR str_2);
/* DOM-NOT_FOR_SDK-END */
/*****************************************************************************
* FUNCTION
* vm_wstarts_with
* DESCRIPTION
* check specified string is started with specified string, and both of the two strings are encoding with UCS2
* PARAMETERS
* s1 : [IN] string to check
* s2 : [IN] starting string
* RETURNS
* 0 if s1 start with s2, else return others.
*****************************************************************************/
VMINT vm_wstarts_with(VMWSTR a, VMWSTR b);
VMINT vm_vwsprintf(VMWSTR outstr, VMINT size, const VMWSTR fmt, va_list args);
VMINT vm_wsprintf(VMWSTR outstr, VMINT size, const VMWSTR fmt, ...);
#ifdef __cplusplus
}
#endif
#endif /* VMSTDLIB_SDK_H_ */