#define OCPF_SUCCESS 0x0
#define OCPF_ERROR 0x1
+#define OCPF_E_EXIST 0x2
#define OCPF_FLAGS_RDWR 0
#define OCPF_FLAGS_READ 1
#define OCPF_FLAGS_CREATE 3
extern struct ocpf *ocpf;
-/* extern unsigned int lineno; */
#endif /* ! __OCPF_H_ */
\param filename pointer to the
\param context_id pointer to the context_id the function returns
\param flags Flags controlling how the OCPF should be opened
+ \param existing boolean returned by the function to specify if the
+ context was already existing or not
\return valid ocpf context pointer on success, otherwise NULL
*/
struct ocpf_context *ocpf_context_add(struct ocpf *ocpf_ctx,
const char *filename,
uint32_t *context_id,
- uint8_t flags)
+ uint8_t flags,
+ bool *existing)
{
struct ocpf_context *el;
struct ocpf_freeid *elf;
if (el->filename && !strcmp(el->filename, filename)) {
*context_id = el->context_id;
el->ref_count += 1;
+ *existing = true;
return el;
}
}
}
/* Initialize the new context */
+ *existing = false;
el = ocpf_context_init(ocpf_ctx->mem_ctx, filename, flags, *context_id);
/* handle the case where file couldn't be opened */
_PUBLIC_ int ocpf_new_context(const char *filename, uint32_t *context_id, uint8_t flags)
{
struct ocpf_context *ctx;
+ bool existing = false;
OCPF_RETVAL_IF(!ocpf || !ocpf->mem_ctx, NULL, OCPF_NOT_INITIALIZED, NULL);
- ctx = ocpf_context_add(ocpf, filename, context_id, flags);
+ ctx = ocpf_context_add(ocpf, filename, context_id, flags, &existing);
if (!ctx) {
return OCPF_ERROR;
}
- DLIST_ADD_END(ocpf->context, ctx, struct ocpf_context *);
+ if (existing == false) {
+ DLIST_ADD_END(ocpf->context, ctx, struct ocpf_context *);
+ return OCPF_SUCCESS;
+ }
- return OCPF_SUCCESS;
+ return OCPF_E_EXIST;
}