author Mike Hommey <mh+mozilla@glandium.org>
Fri, 23 Jun 2017 15:05:06 +0900
changeset 366422 374900b2142af725d4136758ac00dce2fbb824be
parent 307993 de07c5af9cc8975d82cbb5dde8cd2a64dc3d8b42
child 391614 f53d4e3b563526a4191ea488d374cb0ebc7b597e
permissions -rw-r--r--
Bug 1375798 - Reorganize the library_name_info function. r=mshal The function as it currently is matches how things were done in old-configure.in. However, that's just confusing and hard to follow. In fact, the unit test failing numerous times while writing this patch pretty much highlights the problem. So instead of a confusing set of overrides to the prefixes and suffixes, spell out the whole set for each set of platforms. This also happens to make the function shorter. Win/win. At the same time, we normalize the function output as a nested namespace, where we get, for each of dll, lib, import_lib, etc. a prefix/suffix pair. Further down the road, we can imagine changing those to class instances with a method allowing to format file names based on those prefix/suffixes.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "LSBUtils.h"

#include <unistd.h>
#include "base/process_util.h"

namespace mozilla {
namespace widget {
namespace lsb {

static const char* gLsbReleasePath = "/usr/bin/lsb_release";

GetLSBRelease(nsACString& aDistributor,
              nsACString& aDescription,
              nsACString& aRelease,
              nsACString& aCodename)
  if (access(gLsbReleasePath, R_OK) != 0)
    return false;

  int pipefd[2];
  if (pipe(pipefd) == -1) {
    NS_WARNING("pipe() failed!");
    return false;

  std::vector<std::string> argv = {
    gLsbReleasePath, "-idrc"

  std::vector<std::pair<int, int>> fdMap = {
    { pipefd[1], STDOUT_FILENO }

  base::ProcessHandle process;
  base::LaunchApp(argv, fdMap, true, &process);
  if (!process) {
    NS_WARNING("Failed to spawn lsb_release!");
    return false;

  FILE* stream = fdopen(pipefd[0], "r");
  if (!stream) {
    NS_WARNING("Could not wrap fd!");
    return false;

  char dist[256], desc[256], release[256], codename[256];
  if (fscanf(stream, "Distributor ID:\t%255[^\n]\n"
             dist, desc, release, codename) != 4)
    NS_WARNING("Failed to parse lsb_release!");
    return false;

  return true;

}  // namespace lsb
}  // namespace widget
}  // namespace mozilla