MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / new_file_descriptor

Function new_file_descriptor

libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp:61–100  ·  view source on GitHub ↗

allocate a file descriptor */

Source from the content-addressed store, hash-verified

59 allocate a file descriptor
60*/
61static int new_file_descriptor(const char *pathname)
62{
63 int i;
64 FAT_FILE *stream;
65 FIL *fh;
66
67 for (i=0; i<MAX_FILES; ++i) {
68 if (isatty_(i)) {
69 continue;
70 }
71 if (file_table[i] == NULL) {
72 stream = (FAT_FILE *) calloc(sizeof(FAT_FILE),1);
73 if (stream == NULL) {
74 errno = ENOMEM;
75 return -1;
76 }
77 fh = (FIL *) calloc(sizeof(FIL),1);
78 if (fh == NULL) {
79 free(stream);
80 errno = ENOMEM;
81 return -1;
82 }
83 char *fname = (char *)malloc(strlen(pathname)+1);
84 if (fname == NULL) {
85 free(fh);
86 free(stream);
87 errno = ENOMEM;
88 return -1;
89 }
90 strcpy(fname, pathname);
91 stream->name = fname;
92
93 file_table[i] = stream;
94 stream->fh = fh;
95 return i;
96 }
97 }
98 errno = ENFILE;
99 return -1;
100}
101
102static FAT_FILE *fileno_to_stream(int fileno)
103{

Callers 1

openMethod · 0.85

Calls 5

isatty_Function · 0.85
callocFunction · 0.85
freeFunction · 0.85
strlenFunction · 0.85
mallocFunction · 0.50

Tested by

no test coverage detected