Files
OpenCellular/chip/host/persistence.c
Vic Yang 0d99eadd77 Add persistent storage for emulator
This is needed for non-volatile register emulation. Also, this can be
used to implement system jump or reset flags.

BUG=chrome-os-partner:19235
TEST=Run utils test. Check persistent storage file exists.
BRANCH=None

Change-Id: I699f95718ef6f5de6c3bbb4e37619ee015fb6c4a
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/50313
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-05-07 16:02:30 -07:00

43 lines
917 B
C

/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Persistence module for emulator */
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#define BUF_SIZE 1024
static void get_storage_path(char *out)
{
char buf[BUF_SIZE];
readlink("/proc/self/exe", buf, BUF_SIZE);
if (snprintf(out, BUF_SIZE, "%s_persist", buf) >= BUF_SIZE)
out[BUF_SIZE - 1] = '\0';
}
FILE *get_persistent_storage(const char *tag, const char *mode)
{
char buf[BUF_SIZE];
char path[BUF_SIZE];
/*
* The persistent storage with tag 'foo' for test 'bar' would
* be named 'bar_persist_foo'
*/
get_storage_path(buf);
if (snprintf(path, BUF_SIZE, "%s_%s", buf, tag) >= BUF_SIZE)
path[BUF_SIZE - 1] = '\0';
return fopen(path, mode);
}
void release_persistent_storage(FILE *ps)
{
fclose(ps);
}