hocclk: format code
use clang format file provided for optimal formatting
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <crc32.h>
|
||||
@@ -20,7 +20,7 @@
|
||||
namespace crc32 {
|
||||
uint32_t crc32(const uint8_t *data, size_t length) {
|
||||
uint32_t crc = 0xFFFFFFFF;
|
||||
|
||||
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
crc ^= data[i];
|
||||
for (int j = 0; j < 8; j++) {
|
||||
@@ -36,11 +36,11 @@ namespace crc32 {
|
||||
perror("[crc32] Error opening file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint8_t buffer[1024];
|
||||
uint32_t crc = 0xFFFFFFFF;
|
||||
size_t bytes_read;
|
||||
|
||||
|
||||
while ((bytes_read = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||
for (size_t i = 0; i < bytes_read; i++) {
|
||||
crc ^= buffer[i];
|
||||
@@ -49,8 +49,8 @@ namespace crc32 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fclose(file);
|
||||
return ~crc;
|
||||
}
|
||||
}
|
||||
} // namespace crc32
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
namespace crc32 {
|
||||
uint32_t crc32(const uint8_t *data, size_t length);
|
||||
uint32_t checksum_file(const char *filename);
|
||||
}
|
||||
} // namespace crc32
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,57 +24,49 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <mutex>
|
||||
#include <switch.h>
|
||||
#include <mutex>
|
||||
#include <switch.h>
|
||||
|
||||
class LockableMutex
|
||||
{
|
||||
public:
|
||||
LockableMutex()
|
||||
{
|
||||
class LockableMutex {
|
||||
public:
|
||||
LockableMutex() {
|
||||
mutexInit(&this->m);
|
||||
}
|
||||
|
||||
virtual ~LockableMutex() {}
|
||||
virtual ~LockableMutex() {
|
||||
}
|
||||
|
||||
void Lock()
|
||||
{
|
||||
void Lock() {
|
||||
mutexLock(&this->m);
|
||||
}
|
||||
|
||||
bool TryLock()
|
||||
{
|
||||
bool TryLock() {
|
||||
return mutexTryLock(&this->m);
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
|
||||
void Unlock() {
|
||||
mutexUnlock(&this->m);
|
||||
}
|
||||
|
||||
// snake_case aliases in order to implement Lockable
|
||||
|
||||
void lock()
|
||||
{
|
||||
void lock() {
|
||||
this->Lock();
|
||||
}
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
bool try_lock() {
|
||||
return this->TryLock();
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
void unlock() {
|
||||
this->Unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
Mutex m;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,60 +24,48 @@
|
||||
|
||||
#include "memmem.h"
|
||||
|
||||
void *memmem_impl(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
|
||||
{
|
||||
const unsigned char *cmpp;
|
||||
const unsigned char *p;
|
||||
const unsigned char *endp;
|
||||
const unsigned char *q;
|
||||
const unsigned char *endq;
|
||||
unsigned char found;
|
||||
void *memmem_impl(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
|
||||
const unsigned char *cmpp;
|
||||
const unsigned char *p;
|
||||
const unsigned char *endp;
|
||||
const unsigned char *q;
|
||||
const unsigned char *endq;
|
||||
unsigned char found;
|
||||
|
||||
if(haystack == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if(needle == NULL)
|
||||
{
|
||||
return (void*)haystack;
|
||||
}
|
||||
if(haystacklen == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if(needlelen == 0)
|
||||
{
|
||||
return (void*)haystack;
|
||||
}
|
||||
if (haystack == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (needle == NULL) {
|
||||
return (void *)haystack;
|
||||
}
|
||||
if (haystacklen == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (needlelen == 0) {
|
||||
return (void *)haystack;
|
||||
}
|
||||
|
||||
if(needlelen > haystacklen)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (needlelen > haystacklen) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
endp = haystack + haystacklen - needlelen;
|
||||
endq = needle + needlelen;
|
||||
for(p = haystack; p <= endp; p++)
|
||||
{
|
||||
found = 1;
|
||||
cmpp = p;
|
||||
for(q = needle; q < endq; q++)
|
||||
{
|
||||
if(*cmpp != *q)
|
||||
{
|
||||
found = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmpp++;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
return (void*)p;
|
||||
}
|
||||
}
|
||||
endp = haystack + haystacklen - needlelen;
|
||||
endq = needle + needlelen;
|
||||
for (p = haystack; p <= endp; p++) {
|
||||
found = 1;
|
||||
cmpp = p;
|
||||
for (q = needle; q < endq; q++) {
|
||||
if (*cmpp != *q) {
|
||||
found = 0;
|
||||
break;
|
||||
} else {
|
||||
cmpp++;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
return (void *)p;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void *memmem_impl(const void *haystack, size_t haystacklen,
|
||||
const void *needle, size_t needlelen);
|
||||
void *memmem_impl(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -21,25 +21,23 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <switch/types.h>
|
||||
#include <switch/result.h>
|
||||
#include <switch/kernel/mutex.h>
|
||||
#include <switch/sf/service.h>
|
||||
#include <switch/result.h>
|
||||
#include <switch/services/sm.h>
|
||||
#include <switch/sf/service.h>
|
||||
#include <switch/types.h>
|
||||
|
||||
typedef struct ServiceGuard {
|
||||
Mutex mutex;
|
||||
u32 refCount;
|
||||
} ServiceGuard;
|
||||
|
||||
NX_INLINE bool serviceGuardBeginInit(ServiceGuard* g)
|
||||
{
|
||||
NX_INLINE bool serviceGuardBeginInit(ServiceGuard *g) {
|
||||
mutexLock(&g->mutex);
|
||||
return (g->refCount++) == 0;
|
||||
}
|
||||
|
||||
NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupFunc)(void))
|
||||
{
|
||||
NX_INLINE Result serviceGuardEndInit(ServiceGuard *g, Result rc, void (*cleanupFunc)(void)) {
|
||||
if (R_FAILED(rc)) {
|
||||
cleanupFunc();
|
||||
--g->refCount;
|
||||
@@ -48,32 +46,29 @@ NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupF
|
||||
return rc;
|
||||
}
|
||||
|
||||
NX_INLINE void serviceGuardExit(ServiceGuard* g, void (*cleanupFunc)(void))
|
||||
{
|
||||
NX_INLINE void serviceGuardExit(ServiceGuard *g, void (*cleanupFunc)(void)) {
|
||||
mutexLock(&g->mutex);
|
||||
if (g->refCount && (--g->refCount) == 0)
|
||||
cleanupFunc();
|
||||
mutexUnlock(&g->mutex);
|
||||
}
|
||||
|
||||
#define NX_GENERATE_SERVICE_GUARD_PARAMS(name, _paramdecl, _parampass) \
|
||||
\
|
||||
static ServiceGuard g_##name##Guard; \
|
||||
NX_INLINE Result _##name##Initialize _paramdecl; \
|
||||
static void _##name##Cleanup(void); \
|
||||
\
|
||||
Result name##Initialize _paramdecl \
|
||||
{ \
|
||||
Result rc = 0; \
|
||||
if (serviceGuardBeginInit(&g_##name##Guard)) \
|
||||
rc = _##name##Initialize _parampass; \
|
||||
return serviceGuardEndInit(&g_##name##Guard, rc, _##name##Cleanup); \
|
||||
} \
|
||||
\
|
||||
void name##Exit(void) \
|
||||
{ \
|
||||
serviceGuardExit(&g_##name##Guard, _##name##Cleanup); \
|
||||
}
|
||||
#define NX_GENERATE_SERVICE_GUARD_PARAMS(name, _paramdecl, _parampass) \
|
||||
\
|
||||
static ServiceGuard g_##name##Guard; \
|
||||
NX_INLINE Result _##name##Initialize _paramdecl; \
|
||||
static void _##name##Cleanup(void); \
|
||||
\
|
||||
Result name##Initialize _paramdecl { \
|
||||
Result rc = 0; \
|
||||
if (serviceGuardBeginInit(&g_##name##Guard)) \
|
||||
rc = _##name##Initialize _parampass; \
|
||||
return serviceGuardEndInit(&g_##name##Guard, rc, _##name##Cleanup); \
|
||||
} \
|
||||
\
|
||||
void name##Exit(void) { \
|
||||
serviceGuardExit(&g_##name##Guard, _##name##Cleanup); \
|
||||
}
|
||||
|
||||
#define NX_GENERATE_SERVICE_GUARD(name) NX_GENERATE_SERVICE_GUARD_PARAMS(name, (void), ())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user