blob: b2d5f1fa755466bb0878d75defbf106d256f0f7b [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkina9cc46e2004-09-22 16:06:28 +00005#include <asn_internal.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00006#include <asn_types.h> /* for MALLOC/REALLOC/FREEMEM */
7#include <asn_SEQUENCE_OF.h>
8
9typedef A_SEQUENCE_OF(void) asn_sequence;
10
11void
12asn_sequence_del(void *asn_sequence_of_x, int number, int _do_free) {
Lev Walkinc2346572004-08-11 09:07:36 +000013 asn_sequence *as = (asn_sequence *)asn_sequence_of_x;
Lev Walkinf15320b2004-06-03 03:38:44 +000014
15 if(as) {
16 void *ptr;
17 int n;
18
19 if(number < 0 || number >= as->count)
20 return; /* Nothing to delete */
21
22 if(_do_free && as->free) {
23 ptr = as->array[number];
24 } else {
25 ptr = 0;
26 }
27
28 /*
29 * Shift all elements to the left to hide the gap.
30 */
31 --as->count;
32 for(n = number; n < as->count; n++)
33 as->array[n] = as->array[n+1];
34
35 /*
36 * Invoke the third-party function only when the state
37 * of the parent structure is consistent.
38 */
39 if(ptr) as->free(ptr);
40 }
41}
42