with99/include/with99/defres.h
2025-07-26 12:00:08 +05:00

47 lines
997 B
C

#ifndef WITH99_DEFRES_H
#define WITH99_DEFRES_H
#define WITH99_resource_Adhoc_IMPL(var, type, init, deinit) \
ML99_tuple(\
ML99_just(v(type var)),\
ML99_just(v((init, 1))),\
ML99_just(v((deinit)))\
)
#define WITH99_resource_AdhocThrows_IMPL(var, type, init, deinit) \
ML99_tuple(\
ML99_just(v(type var)),\
ML99_just(v((init))),\
ML99_just(v((deinit)))\
)
#define WITH99_resource_Call_IMPL(init, deinit) \
ML99_tuple(\
ML99_nothing(),\
ML99_just(v((init, 1))),\
ML99_just(v((deinit)))\
)
#define WITH99_resource_CallThrows_IMPL(init, deinit) \
ML99_tuple(\
ML99_nothing(),\
ML99_just(v((init))),\
ML99_just(v((deinit)))\
)
#define WITH99_resource_File_IMPL(var, filename, mode) \
ML99_tuple(\
ML99_just(v(FILE* var)),\
ML99_just(v(var = fopen(filename, mode))),\
ML99_just(v(fclose(var)))\
)
#define WITH99_resource_TmpFile_IMPL(var) \
ML99_tuple(\
ML99_just(v(FILE* var)),\
ML99_just(v(var = tmpfile())),\
ML99_just(v(fclose(var)))\
)
#endif