Chapter B2
Full Descriptions of Miscellaneous Functions

Util_CurrentDate

Fills string with current local date

Synopsis

C
#include "cctk.h"  
#include "cctk_Misc.h.h"  
 
int retval = Util_CurrentDate (int len, char *now);


Parameters

len length of the user-supplied string buffer
now user-supplied string buffer to write the date stamp to

Result

retval length of the string returned in now, or 0 if the string was truncated

See Also

Util_CurrentTime [B18] Fills string with current local time
Util_CurrentDateTime [B16] Returns the current datetime in a machine-processable format as defined in ISO 8601 chapter 5.4.

Util_CurrentDateTime

Returns the current datetime in a machine-processable format as defined in ISO 8601 chapter 5.4.

Synopsis

C
#include "cctk.h"  
#include "cctk_Misc.h.h"  
 
char *current_datetime = Util_CurrentDateTime ();


Result

current_datetime Pointer to an allocated formatted string containing the current datetime stamp. The pointer should be freed by the caller.

Discussion

The formatted string returned contains the current datetime in a machine-processable format as defined in ISO 8601 chapter 5.4: "YYYY-MM-DDThh:mm:ss+hh:mm”

See Also

Util_CurrentDate [B15] Fills string with current local date
Util_CurrentTime [B18] Fills string with current local time

Util_CurrentTime

Fills string with current local time

Synopsis

C
#include "cctk.h"  
#include "cctk_Misc.h.h"  
 
int retval = Util_CurrentTime (int len, char *now);


Parameters

len length of the user-supplied string buffer
now user-supplied string buffer to write the time stamp to

Result

retval length of the string returned in now, or 0 if the string was truncated

See Also

Util_CurrentDate [B15] Fills string with current local date
Util_CurrentDateTime [B16] Returns the current datetime in a machine-processable format as defined in ISO 8601 chapter 5.4.

Util_snprintf

Deprecated; use snprintf instead.

Util_vsnprintf

Deprecated; use vsnprintf instead.

Util_asprintf

Sprintf with memory allocation. On input the buffer should point to a NULL area of memory.

Synopsis

C
#include "util_String.h"  
int count = Util_asprintf(char** buffer, const char* format,  
                           va_list arg)


Parameters

buffer Buffer to which to print the string.

*buffer should be NULL on entry. The routine allocates the memory, so the previous contents of the pointer are lost. On exit the buffer size will be count+1 (i.e the length of the string plus the \0).
format A (non-NULL pointer to a) C-style NUL-terminated string describing how to format any further arguments
... Zero or more further arguments, with types as specified by the format argument.

Discussion

This function is identical to sprintf(), except that it allocates a buffer large enough to hold the output including the terminating null byte, and returns a pointer to it via the first argument. This pointer should be passed to free() to release the allocated storage when it is no longer needed.

See Also

asprintf() GNU/BSD C library function which this function tries to clone.
sprintf() Unsafe and dangerous C library function similar to snprintf(), which doesn’t check the buffer length.