File: record.c

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (77 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (3)
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
#include <string.h>
#include "libtest.h"

typedef struct {
  char name[16];
  int32_t value;
} foo_record_t;

EXTERN const char *
foo_get_name(foo_record_t *self)
{
  static char ret[16];
  if(self == NULL)
    return NULL;
  /*
   * TODO: we need to copy the name because the record
   * could fall out of scope before we start processing
   * the return values in ffi_platypus_call.h.  If we
   * can rework that code to delay until after the SV*
   * is created for the return value then we wouldn't
   * need to do this.
   */
  memcpy(ret, self->name, 16);
  return ret;
}

EXTERN const char *
foo_value_get_name(foo_record_t self)
{
  static char name[16];
  strcpy(name, self.name);
  return name;
}

EXTERN int32_t
foo_get_value(foo_record_t *self)
{
  if(self == NULL)
    return 0;
  return self->value;
}

EXTERN int32_t
foo_value_get_value(foo_record_t self)
{
  return self.value;
}

EXTERN foo_record_t *
foo_create(const char *name, int32_t value)
{
  static foo_record_t self;
  int i;

  for(i=0; i<16; i++)
    self.name[i] = '\0';

  strcpy(self.name, name);
  self.value = value;

  return &self;
}

EXTERN foo_record_t
foo_value_create(const char *name, int32_t value)
{
  foo_record_t self;
  int i;

  for(i=0; i<16; i++)
    self.name[i] = '\0';

  strcpy(self.name, name);
  self.value = value;

  return self;
}