Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://doi.org/10.5201/ipol.2011.g_iics
29 June 2020, 11:03:09 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    No releases to show
  • 99c00a5
  • /
  • cwinterp-src
  • /
  • basic.c
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:366601c9924c5c20ae10964c41bb36e65206181a
origin badgedirectory badge
swh:1:dir:1909732c1eb1aa159b7f5bb6f727360f1a51f8b0
origin badgerevision badge
swh:1:rev:2f369309d6656c6bbbe0c0533385c5838cd165bc
origin badgesnapshot badge
swh:1:snp:fdd60cabbff7cf177d6ab66a10db868a837b2d80

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 2f369309d6656c6bbbe0c0533385c5838cd165bc authored by Software Heritage on 01 January 2010, 00:00:00 UTC
ipol: Deposit 692 in collection ipol
Tip revision: 2f36930
basic.c
/** 
 * @file basic.c
 * @brief Memory management, portable types, math constants, and timing
 * @author Pascal Getreuer <getreuer@gmail.com>
 * 
 * This file implements a function Clock, a timer with millisecond
 * precision.  In order to obtain timing at high resolution, platform-
 * specific functions are needed:
 * 
 *    - On Windows systems, the GetSystemTime function is used.
 *    - On UNIX systems, the gettimeofday function is used.
 * 
 * This file attempts to detect whether the platform is Windows or UNIX
 * and defines Clock accordingly. 
 * 
 * 
 * Copyright (c) 2010-2011, Pascal Getreuer
 * All rights reserved.
 * 
 * This program is free software: you can use, modify and/or 
 * redistribute it under the terms of the simplified BSD License. You 
 * should have received a copy of this license along this program. If 
 * not, see <http://www.opensource.org/licenses/bsd-license.html>.
 */

#include <stdlib.h>
#include <stdarg.h>
#include "basic.h"


/** @brief malloc with an error message on failure. */
void *MallocWithErrorMessage(size_t Size)
{
    void *Ptr;
    
    if(!(Ptr = malloc(Size)))
        ErrorMessage("Memory allocation of %u bytes failed.\n", Size);
        
    return Ptr;
}


/** @brief realloc with an error message and free on failure. */
void *ReallocWithErrorMessage(void *Ptr, size_t Size)
{
    void *NewPtr;
    
    if(!(NewPtr = realloc(Ptr, Size)))
    {
        ErrorMessage("Memory reallocation of %u bytes failed.\n", Size);
        Free(Ptr);  /* Free the previous block on failure */
    }
        
    return NewPtr;
}


/** @brief Redefine this function to customize error messages. */
void ErrorMessage(const char *Format, ...)
{
    va_list Args;
    
    va_start(Args, Format);
    /* Write a formatted error message to stderr */
    vfprintf(stderr, Format, Args);
    va_end(Args);
}


#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
/* Windows: implement with GetSystemTime */
	
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

/* Clock:  Get the system clock in milliseconds */
unsigned long Clock()
{
	static SYSTEMTIME TimeVal;
	GetSystemTime(&TimeVal);
	return (unsigned long)((unsigned long)TimeVal.wMilliseconds
		+ 1000*((unsigned long)TimeVal.wSecond
		+ 60*((unsigned long)TimeVal.wMinute 
		+ 60*((unsigned long)TimeVal.wHour 
		+ 24*(unsigned long)TimeVal.wDay))));
}

#else
/* UNIX: implement with gettimeofday */

#include <sys/time.h>
#include <unistd.h>

/* Clock:  Get the system clock in milliseconds */
unsigned long Clock()
{
	struct timeval TimeVal;
	gettimeofday(&TimeVal, NULL); 
	return (unsigned long)(TimeVal.tv_usec/1000 + TimeVal.tv_sec*1000);
}

#endif

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API