Add some platform abstractions.

(This is a merge of http://go/wvgerrit/70303)

This adds a platform.h file to abstract some of the differences
between Windows and POSIX platforms.  This includes ntohl, setenv,
and ssize_t.

Bug: 122953649
Test: Android Unit Tests
Change-Id: I3235f3f284b53d24d7365ff3f4a06dcd9b403697
This commit is contained in:
John W. Bruce
2019-01-15 16:53:22 -08:00
parent 1cd093795e
commit 777abaef01
21 changed files with 74 additions and 20 deletions

View File

@@ -7,12 +7,13 @@
#ifndef WVCDM_UTIL_FILE_STORE_H_
#define WVCDM_UTIL_FILE_STORE_H_
#include <unistd.h>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "disallow_copy_and_assign.h"
#include "platform.h"
#include "util_common.h"
namespace wvcdm {

View File

@@ -0,0 +1,33 @@
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine Master
// License Agreement.
//
// Platform - Abstracts some utilities between platforms.
//
#ifndef WVCDM_UTIL_PLATFORM_H_
#define WVCDM_UTIL_PLATFORM_H_
#include "util_common.h"
#ifdef _WIN32
# include <wtypes.h>
# include <BaseTsd.h>
# include <winsock2.h> // For htonl and ntohl.
# define __PRETTY_FUNCTION__ __FUNCTION__
# undef NO_ERROR
# undef GetCurrentTime
# undef DeleteFile
using ssize_t = SSIZE_T;
inline void sleep(int seconds) {
Sleep(seconds * 1000);
}
CORE_UTIL_EXPORT int setenv(const char* key, const char* value, int overwrite);
#else
# include <arpa/inet.h>
# include <sys/types.h>
# include <unistd.h>
#endif
#endif // WVCDM_UTIL_PLATFORM_H_

View File

@@ -0,0 +1,21 @@
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#include "platform.h"
#include "stdlib.h"
#ifdef _WIN32
int setenv(const char* key, const char* value, int overwrite) {
if (!overwrite) {
size_t size;
errno_t err = getenv_s(&size, nullptr, 0, key);
if (err != 0 || size != 0)
return err; // Return 0 if it exists, but don't change.
}
return _putenv_s(key, value);
}
#endif

View File

@@ -4,7 +4,6 @@
#include "string_conversions.h"
#include <arpa/inet.h>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
@@ -13,6 +12,7 @@
#include <vector>
#include "log.h"
#include "platform.h"
namespace wvcdm {